use of org.apache.lucene.facet.sortedset.SortedSetDocValuesFacetCounts in project lucene-solr by apache.
the class SimpleSortedSetFacetsExample method search.
/** User runs a query and counts facets. */
private List<FacetResult> search() throws IOException {
DirectoryReader indexReader = DirectoryReader.open(indexDir);
IndexSearcher searcher = new IndexSearcher(indexReader);
SortedSetDocValuesReaderState state = new DefaultSortedSetDocValuesReaderState(indexReader);
// Aggregatses the facet counts
FacetsCollector fc = new FacetsCollector();
// MatchAllDocsQuery is for "browsing" (counts facets
// for all non-deleted docs in the index); normally
// you'd use a "normal" query:
FacetsCollector.search(searcher, new MatchAllDocsQuery(), 10, fc);
// Retrieve results
Facets facets = new SortedSetDocValuesFacetCounts(state, fc);
List<FacetResult> results = new ArrayList<>();
results.add(facets.getTopChildren(10, "Author"));
results.add(facets.getTopChildren(10, "Publish Year"));
indexReader.close();
return results;
}
use of org.apache.lucene.facet.sortedset.SortedSetDocValuesFacetCounts in project lucene-solr by apache.
the class SimpleSortedSetFacetsExample method drillDown.
/** User drills down on 'Publish Year/2010'. */
private FacetResult drillDown() throws IOException {
DirectoryReader indexReader = DirectoryReader.open(indexDir);
IndexSearcher searcher = new IndexSearcher(indexReader);
SortedSetDocValuesReaderState state = new DefaultSortedSetDocValuesReaderState(indexReader);
// Now user drills down on Publish Year/2010:
DrillDownQuery q = new DrillDownQuery(config);
q.add("Publish Year", "2010");
FacetsCollector fc = new FacetsCollector();
FacetsCollector.search(searcher, q, 10, fc);
// Retrieve results
Facets facets = new SortedSetDocValuesFacetCounts(state, fc);
FacetResult result = facets.getTopChildren(10, "Author");
indexReader.close();
return result;
}
use of org.apache.lucene.facet.sortedset.SortedSetDocValuesFacetCounts in project searchcode-server by boyter.
the class CodeSearcher method getLanguageFacetResults.
/**
* Returns the matching language facets for a given query
*/
private List<CodeFacetLanguage> getLanguageFacetResults(IndexSearcher searcher, IndexReader reader, Query query) {
List<CodeFacetLanguage> codeFacetLanguages = new ArrayList<>();
try {
SortedSetDocValuesReaderState state = new DefaultSortedSetDocValuesReaderState(reader, Values.LANGUAGENAME);
FacetsCollector fc = new FacetsCollector();
FacetsCollector.search(searcher, query, 10, fc);
Facets facets = new SortedSetDocValuesFacetCounts(state, fc);
FacetResult result = facets.getTopChildren(200, Values.LANGUAGENAME);
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) {
codeFacetLanguages.add(new CodeFacetLanguage(lv.label, lv.value.intValue()));
}
}
}
} catch (IOException ex) {
} catch (Exception ex) {
}
return codeFacetLanguages;
}
use of org.apache.lucene.facet.sortedset.SortedSetDocValuesFacetCounts 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.sortedset.SortedSetDocValuesFacetCounts in project searchcode-server by boyter.
the class TimeCodeSearcher 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) {
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 codeFacetRepo;
}
Aggregations