Search in sources :

Example 6 with DrillDownQuery

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

the class SimpleFacetsExample method drillSideways.

/** User drills down on 'Publish Date/2010', and we
   *  return facets for both 'Publish Date' and 'Author',
   *  using DrillSideways. */
private List<FacetResult> drillSideways() 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");
    DrillSideways ds = new DrillSideways(searcher, config, taxoReader);
    DrillSidewaysResult result = ds.search(q, 10);
    // Retrieve results
    List<FacetResult> facets = result.facets.getAllDims(10);
    indexReader.close();
    taxoReader.close();
    return facets;
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) DrillSidewaysResult(org.apache.lucene.facet.DrillSideways.DrillSidewaysResult) DirectoryReader(org.apache.lucene.index.DirectoryReader) TaxonomyReader(org.apache.lucene.facet.taxonomy.TaxonomyReader) DirectoryTaxonomyReader(org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader) DrillDownQuery(org.apache.lucene.facet.DrillDownQuery) DrillSideways(org.apache.lucene.facet.DrillSideways) FacetResult(org.apache.lucene.facet.FacetResult) DirectoryTaxonomyReader(org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader)

Example 7 with DrillDownQuery

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

the class RangeFacetsExample method drillDown.

/** User drills down on the specified range. */
public TopDocs drillDown(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));
    return searcher.search(q, 10);
}
Also used : DrillDownQuery(org.apache.lucene.facet.DrillDownQuery)

Example 8 with DrillDownQuery

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

the class SimpleFacetsExample 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;
}
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) DrillDownQuery(org.apache.lucene.facet.DrillDownQuery) FacetResult(org.apache.lucene.facet.FacetResult) DirectoryTaxonomyReader(org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader) FacetsCollector(org.apache.lucene.facet.FacetsCollector)

Example 9 with DrillDownQuery

use of org.apache.lucene.facet.DrillDownQuery 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 10 with DrillDownQuery

use of org.apache.lucene.facet.DrillDownQuery 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

DrillDownQuery (org.apache.lucene.facet.DrillDownQuery)17 IndexSearcher (org.apache.lucene.search.IndexSearcher)14 Facets (org.apache.lucene.facet.Facets)12 FacetsCollector (org.apache.lucene.facet.FacetsCollector)12 FacetResult (org.apache.lucene.facet.FacetResult)8 Document (org.apache.lucene.document.Document)7 FacetsConfig (org.apache.lucene.facet.FacetsConfig)7 TaxonomyReader (org.apache.lucene.facet.taxonomy.TaxonomyReader)7 DirectoryTaxonomyReader (org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader)7 DirectoryReader (org.apache.lucene.index.DirectoryReader)7 Directory (org.apache.lucene.store.Directory)7 DrillSideways (org.apache.lucene.facet.DrillSideways)6 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)6 DrillSidewaysResult (org.apache.lucene.facet.DrillSideways.DrillSidewaysResult)4 MultiFacets (org.apache.lucene.facet.MultiFacets)4 IndexReader (org.apache.lucene.index.IndexReader)4 DoublePoint (org.apache.lucene.document.DoublePoint)3 LongPoint (org.apache.lucene.document.LongPoint)3 FacetField (org.apache.lucene.facet.FacetField)3 DoubleValuesSource (org.apache.lucene.search.DoubleValuesSource)3