use of org.apache.lucene.facet.FacetResult 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.FacetResult in project lucene-solr by apache.
the class MultiCategoryListsFacetsExample 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);
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<>();
// Count both "Publish Date" and "Author" dimensions
Facets author = new FastTaxonomyFacetCounts("author", taxoReader, config, fc);
results.add(author.getTopChildren(10, "Author"));
Facets pubDate = new FastTaxonomyFacetCounts("pubdate", taxoReader, config, fc);
results.add(pubDate.getTopChildren(10, "Publish Date"));
indexReader.close();
taxoReader.close();
return results;
}
use of org.apache.lucene.facet.FacetResult in project lucene-solr by apache.
the class SimpleFacetsExample 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(), fc);
// Retrieve results
List<FacetResult> results = new ArrayList<>();
// 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.FacetResult in project lucene-solr by apache.
the class TestDistanceFacetsExample method testSimple.
public void testSimple() throws Exception {
DistanceFacetsExample example = new DistanceFacetsExample();
example.index();
FacetResult result = example.search();
assertEquals("dim=field path=[] value=3 childCount=4\n < 1 km (1)\n < 2 km (2)\n < 5 km (2)\n < 10 km (3)\n", result.toString());
example.close();
}
use of org.apache.lucene.facet.FacetResult in project lucene-solr by apache.
the class TestRangeFacetsExample method testSimple.
@Test
public void testSimple() throws Exception {
RangeFacetsExample example = new RangeFacetsExample();
example.index();
FacetResult result = example.search();
assertEquals("dim=timestamp path=[] value=87 childCount=3\n Past hour (4)\n Past six hours (22)\n Past day (87)\n", result.toString());
example.close();
}
Aggregations