use of org.apache.lucene.facet.FacetsCollector in project orientdb by orientechnologies.
the class LuceneNativeFacet method facetsWithSearch.
/**
* User runs a query and counts facets.
*/
private List<FacetResult> facetsWithSearch() throws IOException {
DirectoryReader indexReader = DirectoryReader.open(indexDir);
IndexSearcher searcher = new IndexSearcher(indexReader);
TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);
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
List<FacetResult> results = new ArrayList<FacetResult>();
// Count both "Publish Date" and "Author" dimensions
Facets facets = new FastTaxonomyFacetCounts(taxoReader, config, fc);
results.add(facets.getTopChildren(10, "Author"));
results.add(facets.getTopChildren(10, "Publish Date"));
indexReader.close();
taxoReader.close();
return results;
}
use of org.apache.lucene.facet.FacetsCollector in project orientdb by orientechnologies.
the class LuceneNativeFacet method facetsOnly.
/**
* User runs a query and counts facets only without collecting the matching documents.
*/
private List<FacetResult> facetsOnly() throws IOException {
DirectoryReader indexReader = DirectoryReader.open(indexDir);
IndexSearcher searcher = new IndexSearcher(indexReader);
TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);
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:
searcher.search(new MatchAllDocsQuery(), null, /* Filter */
fc);
// Retrieve results
List<FacetResult> results = new ArrayList<FacetResult>();
// Count both "Publish Date" and "Author" dimensions
Facets facets = new FastTaxonomyFacetCounts(taxoReader, config, fc);
results.add(facets.getTopChildren(10, "Author"));
results.add(facets.getTopChildren(10, "Publish Date"));
indexReader.close();
taxoReader.close();
return results;
}
use of org.apache.lucene.facet.FacetsCollector in project orientdb by orientechnologies.
the class LuceneNativeFacet method drillDown.
/**
* User drills down on 'Publish Date/2010', and we return facets for 'Author'
*/
private FacetResult drillDown() throws IOException {
DirectoryReader indexReader = DirectoryReader.open(indexDir);
IndexSearcher searcher = new IndexSearcher(indexReader);
TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);
// Passing no baseQuery means we drill down on all
// documents ("browse only"):
DrillDownQuery q = new DrillDownQuery(config);
// Now user drills down on Publish Date/2010:
q.add("Publish Date", "2010");
FacetsCollector fc = new FacetsCollector();
FacetsCollector.search(searcher, q, 10, fc);
// Retrieve results
Facets facets = new FastTaxonomyFacetCounts(taxoReader, config, fc);
FacetResult result = facets.getTopChildren(10, "Author");
indexReader.close();
taxoReader.close();
return result;
}
use of org.apache.lucene.facet.FacetsCollector in project jackrabbit-oak by apache.
the class FacetHelper method getFacets.
public static Facets getFacets(IndexSearcher searcher, Query query, TopDocs docs, QueryIndex.IndexPlan plan, boolean secure) throws IOException {
Facets facets = null;
@SuppressWarnings("unchecked") List<String> facetFields = (List<String>) plan.getAttribute(ATTR_FACET_FIELDS);
if (facetFields != null && facetFields.size() > 0) {
Map<String, Facets> facetsMap = new HashMap<String, Facets>();
for (String facetField : facetFields) {
FacetsCollector facetsCollector = new FacetsCollector();
try {
DefaultSortedSetDocValuesReaderState state = new DefaultSortedSetDocValuesReaderState(searcher.getIndexReader(), FieldNames.createFacetFieldName(facetField));
FacetsCollector.search(searcher, query, 10, facetsCollector);
facetsMap.put(facetField, secure ? new FilteredSortedSetDocValuesFacetCounts(state, facetsCollector, plan.getFilter(), docs) : new SortedSetDocValuesFacetCounts(state, facetsCollector));
} catch (IllegalArgumentException iae) {
LOGGER.warn("facets for {} not yet indexed", facetField);
}
}
if (facetsMap.size() > 0) {
facets = new MultiFacets(facetsMap);
}
}
return facets;
}
use of org.apache.lucene.facet.FacetsCollector in project lucene-solr by apache.
the class TestOrdinalMappingLeafReader method verifyResults.
private void verifyResults(Directory indexDir, Directory taxoDir) throws IOException {
DirectoryReader indexReader = DirectoryReader.open(indexDir);
DirectoryTaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);
IndexSearcher searcher = newSearcher(indexReader);
FacetsCollector collector = new FacetsCollector();
FacetsCollector.search(searcher, new MatchAllDocsQuery(), 10, collector);
// tag facets
Facets tagFacets = new FastTaxonomyFacetCounts("$tags", taxoReader, facetConfig, collector);
FacetResult result = tagFacets.getTopChildren(10, "tag");
for (LabelAndValue lv : result.labelValues) {
if (VERBOSE) {
System.out.println(lv);
}
assertEquals(NUM_DOCS, lv.value.intValue());
}
// id facets
Facets idFacets = new FastTaxonomyFacetCounts(taxoReader, facetConfig, collector);
FacetResult idResult = idFacets.getTopChildren(10, "id");
assertEquals(NUM_DOCS, idResult.childCount);
// each "id" appears twice
assertEquals(NUM_DOCS * 2, idResult.value);
BinaryDocValues bdv = MultiDocValues.getBinaryValues(indexReader, "bdv");
BinaryDocValues cbdv = MultiDocValues.getBinaryValues(indexReader, "cbdv");
for (int i = 0; i < indexReader.maxDoc(); i++) {
assertEquals(i, bdv.nextDoc());
assertEquals(i, cbdv.nextDoc());
assertEquals(Integer.parseInt(cbdv.binaryValue().utf8ToString()), Integer.parseInt(bdv.binaryValue().utf8ToString()) * 2);
}
IOUtils.close(indexReader, taxoReader);
}
Aggregations