Search in sources :

Example 1 with FastTaxonomyFacetCounts

use of org.apache.lucene.facet.taxonomy.FastTaxonomyFacetCounts 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;
}
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 2 with FastTaxonomyFacetCounts

use of org.apache.lucene.facet.taxonomy.FastTaxonomyFacetCounts 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;
}
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 3 with FastTaxonomyFacetCounts

use of org.apache.lucene.facet.taxonomy.FastTaxonomyFacetCounts 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;
}
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 4 with FastTaxonomyFacetCounts

use of org.apache.lucene.facet.taxonomy.FastTaxonomyFacetCounts 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 5 with FastTaxonomyFacetCounts

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

the class DrillSideways method buildFacetsResult.

/**
   * Subclass can override to customize per-dim Facets
   * impl.
   */
protected Facets buildFacetsResult(FacetsCollector drillDowns, FacetsCollector[] drillSideways, String[] drillSidewaysDims) throws IOException {
    Facets drillDownFacets;
    Map<String, Facets> drillSidewaysFacets = new HashMap<>();
    if (taxoReader != null) {
        drillDownFacets = new FastTaxonomyFacetCounts(taxoReader, config, drillDowns);
        if (drillSideways != null) {
            for (int i = 0; i < drillSideways.length; i++) {
                drillSidewaysFacets.put(drillSidewaysDims[i], new FastTaxonomyFacetCounts(taxoReader, config, drillSideways[i]));
            }
        }
    } else {
        drillDownFacets = new SortedSetDocValuesFacetCounts(state, drillDowns);
        if (drillSideways != null) {
            for (int i = 0; i < drillSideways.length; i++) {
                drillSidewaysFacets.put(drillSidewaysDims[i], new SortedSetDocValuesFacetCounts(state, drillSideways[i]));
            }
        }
    }
    if (drillSidewaysFacets.isEmpty()) {
        return drillDownFacets;
    } else {
        return new MultiFacets(drillSidewaysFacets, drillDownFacets);
    }
}
Also used : FastTaxonomyFacetCounts(org.apache.lucene.facet.taxonomy.FastTaxonomyFacetCounts) HashMap(java.util.HashMap) SortedSetDocValuesFacetCounts(org.apache.lucene.facet.sortedset.SortedSetDocValuesFacetCounts)

Aggregations

FastTaxonomyFacetCounts (org.apache.lucene.facet.taxonomy.FastTaxonomyFacetCounts)10 TaxonomyReader (org.apache.lucene.facet.taxonomy.TaxonomyReader)8 DirectoryTaxonomyReader (org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader)8 IndexSearcher (org.apache.lucene.search.IndexSearcher)8 FacetResult (org.apache.lucene.facet.FacetResult)7 Facets (org.apache.lucene.facet.Facets)7 FacetsCollector (org.apache.lucene.facet.FacetsCollector)7 DirectoryReader (org.apache.lucene.index.DirectoryReader)7 ArrayList (java.util.ArrayList)5 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)5 DrillDownQuery (org.apache.lucene.facet.DrillDownQuery)2 HashMap (java.util.HashMap)1 Random (java.util.Random)1 Document (org.apache.lucene.document.Document)1 StringField (org.apache.lucene.document.StringField)1 MatchingDocs (org.apache.lucene.facet.FacetsCollector.MatchingDocs)1 SortedSetDocValuesFacetCounts (org.apache.lucene.facet.sortedset.SortedSetDocValuesFacetCounts)1 CachedOrdinalsReader (org.apache.lucene.facet.taxonomy.CachedOrdinalsReader)1 DocValuesOrdinalsReader (org.apache.lucene.facet.taxonomy.DocValuesOrdinalsReader)1 OrdinalsReader (org.apache.lucene.facet.taxonomy.OrdinalsReader)1