Search in sources :

Example 56 with Facets

use of org.apache.lucene.facet.Facets 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;
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) SortedSetDocValuesReaderState(org.apache.lucene.facet.sortedset.SortedSetDocValuesReaderState) DefaultSortedSetDocValuesReaderState(org.apache.lucene.facet.sortedset.DefaultSortedSetDocValuesReaderState) Facets(org.apache.lucene.facet.Facets) DirectoryReader(org.apache.lucene.index.DirectoryReader) DefaultSortedSetDocValuesReaderState(org.apache.lucene.facet.sortedset.DefaultSortedSetDocValuesReaderState) ArrayList(java.util.ArrayList) SortedSetDocValuesFacetCounts(org.apache.lucene.facet.sortedset.SortedSetDocValuesFacetCounts) FacetResult(org.apache.lucene.facet.FacetResult) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) FacetsCollector(org.apache.lucene.facet.FacetsCollector)

Example 57 with Facets

use of org.apache.lucene.facet.Facets 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;
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) SortedSetDocValuesReaderState(org.apache.lucene.facet.sortedset.SortedSetDocValuesReaderState) DefaultSortedSetDocValuesReaderState(org.apache.lucene.facet.sortedset.DefaultSortedSetDocValuesReaderState) Facets(org.apache.lucene.facet.Facets) DirectoryReader(org.apache.lucene.index.DirectoryReader) DrillDownQuery(org.apache.lucene.facet.DrillDownQuery) DefaultSortedSetDocValuesReaderState(org.apache.lucene.facet.sortedset.DefaultSortedSetDocValuesReaderState) SortedSetDocValuesFacetCounts(org.apache.lucene.facet.sortedset.SortedSetDocValuesFacetCounts) FacetResult(org.apache.lucene.facet.FacetResult) FacetsCollector(org.apache.lucene.facet.FacetsCollector)

Example 58 with Facets

use of org.apache.lucene.facet.Facets 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;
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) FastTaxonomyFacetCounts(org.apache.lucene.facet.taxonomy.FastTaxonomyFacetCounts) Facets(org.apache.lucene.facet.Facets) DirectoryReader(org.apache.lucene.index.DirectoryReader) TaxonomyReader(org.apache.lucene.facet.taxonomy.TaxonomyReader) DirectoryTaxonomyReader(org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader) ArrayList(java.util.ArrayList) FacetResult(org.apache.lucene.facet.FacetResult) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) DirectoryTaxonomyReader(org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader) FacetsCollector(org.apache.lucene.facet.FacetsCollector)

Example 59 with Facets

use of org.apache.lucene.facet.Facets in project lucene-solr by apache.

the class RangeFacetsExample method search.

/** User runs a query and counts facets. */
public FacetResult search() throws IOException {
    // Aggregates 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);
    Facets facets = new LongRangeFacetCounts("timestamp", fc, PAST_HOUR, PAST_SIX_HOURS, PAST_DAY);
    return facets.getTopChildren(10, "timestamp");
}
Also used : Facets(org.apache.lucene.facet.Facets) LongRangeFacetCounts(org.apache.lucene.facet.range.LongRangeFacetCounts) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) FacetsCollector(org.apache.lucene.facet.FacetsCollector)

Example 60 with Facets

use of org.apache.lucene.facet.Facets in project lucene-solr by apache.

the class RangeFacetsExample method drillSideways.

/** User drills down on the specified range, and also computes drill sideways counts. */
public DrillSideways.DrillSidewaysResult drillSideways(LongRange range) throws IOException {
    // Passing no baseQuery means we drill down on all
    // documents ("browse only"):
    DrillDownQuery q = new DrillDownQuery(getConfig());
    q.add("timestamp", LongPoint.newRangeQuery("timestamp", range.min, range.max));
    // DrillSideways only handles taxonomy and sorted set drill facets by default; to do range facets we must subclass and override the
    // buildFacetsResult method.
    DrillSideways.DrillSidewaysResult result = new DrillSideways(searcher, getConfig(), null, null) {

        @Override
        protected Facets buildFacetsResult(FacetsCollector drillDowns, FacetsCollector[] drillSideways, String[] drillSidewaysDims) throws IOException {
            // If we had other dims we would also compute their drill-down or drill-sideways facets here:
            assert drillSidewaysDims[0].equals("timestamp");
            return new LongRangeFacetCounts("timestamp", drillSideways[0], PAST_HOUR, PAST_SIX_HOURS, PAST_DAY);
        }
    }.search(q, 10);
    return result;
}
Also used : Facets(org.apache.lucene.facet.Facets) LongRangeFacetCounts(org.apache.lucene.facet.range.LongRangeFacetCounts) DrillDownQuery(org.apache.lucene.facet.DrillDownQuery) DrillSideways(org.apache.lucene.facet.DrillSideways) IOException(java.io.IOException) FacetsCollector(org.apache.lucene.facet.FacetsCollector)

Aggregations

Facets (org.apache.lucene.facet.Facets)72 FacetsCollector (org.apache.lucene.facet.FacetsCollector)60 FacetResult (org.apache.lucene.facet.FacetResult)47 IndexSearcher (org.apache.lucene.search.IndexSearcher)46 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)37 DirectoryTaxonomyReader (org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader)35 Directory (org.apache.lucene.store.Directory)34 Document (org.apache.lucene.document.Document)32 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)32 FacetsConfig (org.apache.lucene.facet.FacetsConfig)29 DirectoryReader (org.apache.lucene.index.DirectoryReader)27 LabelAndValue (org.apache.lucene.facet.LabelAndValue)23 DirectoryTaxonomyWriter (org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter)22 FacetField (org.apache.lucene.facet.FacetField)19 ArrayList (java.util.ArrayList)18 IOException (java.io.IOException)14 DefaultSortedSetDocValuesReaderState (org.apache.lucene.facet.sortedset.DefaultSortedSetDocValuesReaderState)14 SortedSetDocValuesFacetCounts (org.apache.lucene.facet.sortedset.SortedSetDocValuesFacetCounts)14 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)13 DrillDownQuery (org.apache.lucene.facet.DrillDownQuery)13