use of org.apache.lucene.facet.FacetResult in project searchcode-server by boyter.
the class CodeSearcher method getOwnerFacetResults.
/**
* Returns the matching owner facets for a given query
*/
private List<CodeFacetOwner> getOwnerFacetResults(IndexSearcher searcher, IndexReader reader, Query query) {
List<CodeFacetOwner> codeFacetRepo = new ArrayList<>();
try {
SortedSetDocValuesReaderState state = new DefaultSortedSetDocValuesReaderState(reader, Values.CODEOWNER);
FacetsCollector fc = new FacetsCollector();
FacetsCollector.search(searcher, query, 10, fc);
Facets facets = new SortedSetDocValuesFacetCounts(state, fc);
FacetResult result = facets.getTopChildren(200, Values.CODEOWNER);
if (result != null) {
int stepThru = result.childCount > 200 ? 200 : result.childCount;
for (int i = 0; i < stepThru; i++) {
LabelAndValue lv = result.labelValues[i];
if (lv != null && lv.value != null) {
codeFacetRepo.add(new CodeFacetOwner(lv.label, lv.value.intValue()));
}
}
}
} catch (IOException ex) {
} catch (Exception ex) {
}
return codeFacetRepo;
}
use of org.apache.lucene.facet.FacetResult in project orientdb by orientechnologies.
the class LuceneNativeFacet method main.
/**
* Runs the search and drill-down examples and prints the results.
*/
public static void main(String[] args) throws Exception {
System.out.println("Facet counting example:");
System.out.println("-----------------------");
LuceneNativeFacet example = new LuceneNativeFacet();
List<FacetResult> results1 = example.runFacetOnly();
System.out.println("Author: " + results1.get(0));
System.out.println("Publish Date: " + results1.get(1));
System.out.println("Facet counting example (combined facets and search):");
System.out.println("-----------------------");
List<FacetResult> results = example.runSearch();
System.out.println("Author: " + results.get(0));
System.out.println("Publish Date: " + results.get(1));
System.out.println("Facet drill-down example (Publish Date/2010):");
System.out.println("---------------------------------------------");
System.out.println("Author: " + example.runDrillDown());
System.out.println("Facet drill-sideways example (Publish Date/2010):");
System.out.println("---------------------------------------------");
for (FacetResult result : example.runDrillSideways()) {
System.out.println(result);
}
}
use of org.apache.lucene.facet.FacetResult in project searchcode-server by boyter.
the class TimeCodeSearcher method getYearFacetResults.
/**
* Returns the matching yearmonth facets for a given query
*/
private List<CodeFacetYear> getYearFacetResults(IndexSearcher searcher, IndexReader reader, Query query) {
List<CodeFacetYear> codeFacetYear = new ArrayList<>();
try {
SortedSetDocValuesReaderState state = new DefaultSortedSetDocValuesReaderState(reader, Values.DATEYEAR);
FacetsCollector fc = new FacetsCollector();
FacetsCollector.search(searcher, query, 10, fc);
Facets facets = new SortedSetDocValuesFacetCounts(state, fc);
FacetResult result = facets.getTopChildren(200, Values.DATEYEAR);
if (result != null) {
int stepThru = result.childCount > 200 ? 200 : result.childCount;
for (int i = 0; i < stepThru; i++) {
LabelAndValue lv = result.labelValues[i];
if (lv != null && lv.value != null) {
codeFacetYear.add(new CodeFacetYear(lv.label, lv.value.intValue()));
}
}
}
} catch (IOException ex) {
// LOGGER.warning(" caught a " + ex.getClass() + "\n with message: " + ex.getMessage());
} catch (Exception ex) {
// LOGGER.warning(" caught a " + ex.getClass() + "\n with message: " + ex.getMessage());
}
return codeFacetYear;
}
use of org.apache.lucene.facet.FacetResult in project searchcode-server by boyter.
the class TimeCodeSearcher method getDeletedFacetResults.
/**
* Returns the matching revision facets for a given query
*/
private List<CodeFacetDeleted> getDeletedFacetResults(IndexSearcher searcher, IndexReader reader, Query query) {
List<CodeFacetDeleted> deletedFacets = new ArrayList<>();
try {
SortedSetDocValuesReaderState state = new DefaultSortedSetDocValuesReaderState(reader, Values.DELETED);
FacetsCollector fc = new FacetsCollector();
FacetsCollector.search(searcher, query, 10, fc);
Facets facets = new SortedSetDocValuesFacetCounts(state, fc);
FacetResult result = facets.getTopChildren(200, Values.DELETED);
if (result != null) {
int stepThru = result.childCount > 200 ? 200 : result.childCount;
for (int i = 0; i < stepThru; i++) {
LabelAndValue lv = result.labelValues[i];
if (lv != null && lv.value != null) {
deletedFacets.add(new CodeFacetDeleted(lv.label, lv.value.intValue()));
}
}
}
} catch (IOException ex) {
// LOGGER.warning(" caught a " + ex.getClass() + "\n with message: " + ex.getMessage());
} catch (Exception ex) {
// LOGGER.warning(" caught a " + ex.getClass() + "\n with message: " + ex.getMessage());
}
return deletedFacets;
}
use of org.apache.lucene.facet.FacetResult in project searchcode-server by boyter.
the class TimeCodeSearcher method getRevisionFacetResults.
/**
* Returns the matching revision facets for a given query
*/
private List<CodeFacetRevision> getRevisionFacetResults(IndexSearcher searcher, IndexReader reader, Query query) {
List<CodeFacetRevision> revisionFacets = new ArrayList<>();
try {
SortedSetDocValuesReaderState state = new DefaultSortedSetDocValuesReaderState(reader, Values.REVISION);
FacetsCollector fc = new FacetsCollector();
FacetsCollector.search(searcher, query, 10, fc);
Facets facets = new SortedSetDocValuesFacetCounts(state, fc);
FacetResult result = facets.getTopChildren(200, Values.REVISION);
if (result != null) {
int stepThru = result.childCount > 200 ? 200 : result.childCount;
for (int i = 0; i < stepThru; i++) {
LabelAndValue lv = result.labelValues[i];
if (lv != null && lv.value != null) {
revisionFacets.add(new CodeFacetRevision(lv.label, lv.value.intValue()));
}
}
}
} catch (IOException ex) {
// LOGGER.warning(" caught a " + ex.getClass() + "\n with message: " + ex.getMessage());
} catch (Exception ex) {
// LOGGER.warning(" caught a " + ex.getClass() + "\n with message: " + ex.getMessage());
}
return revisionFacets;
}
Aggregations