Search in sources :

Example 1 with TaxonomyFacetSumIntAssociations

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

the class AssociationsFacetsExample method sumAssociations.

/** User runs a query and aggregates facets by summing their association values. */
private List<FacetResult> sumAssociations() 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);
    Facets tags = new TaxonomyFacetSumIntAssociations("$tags", taxoReader, config, fc);
    Facets genre = new TaxonomyFacetSumFloatAssociations("$genre", taxoReader, config, fc);
    // Retrieve results
    List<FacetResult> results = new ArrayList<>();
    results.add(tags.getTopChildren(10, "tags"));
    results.add(genre.getTopChildren(10, "genre"));
    indexReader.close();
    taxoReader.close();
    return results;
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) 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) TaxonomyFacetSumIntAssociations(org.apache.lucene.facet.taxonomy.TaxonomyFacetSumIntAssociations) FacetResult(org.apache.lucene.facet.FacetResult) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) TaxonomyFacetSumFloatAssociations(org.apache.lucene.facet.taxonomy.TaxonomyFacetSumFloatAssociations) DirectoryTaxonomyReader(org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader) FacetsCollector(org.apache.lucene.facet.FacetsCollector)

Aggregations

ArrayList (java.util.ArrayList)1 FacetResult (org.apache.lucene.facet.FacetResult)1 Facets (org.apache.lucene.facet.Facets)1 FacetsCollector (org.apache.lucene.facet.FacetsCollector)1 TaxonomyFacetSumFloatAssociations (org.apache.lucene.facet.taxonomy.TaxonomyFacetSumFloatAssociations)1 TaxonomyFacetSumIntAssociations (org.apache.lucene.facet.taxonomy.TaxonomyFacetSumIntAssociations)1 TaxonomyReader (org.apache.lucene.facet.taxonomy.TaxonomyReader)1 DirectoryTaxonomyReader (org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader)1 DirectoryReader (org.apache.lucene.index.DirectoryReader)1 IndexSearcher (org.apache.lucene.search.IndexSearcher)1 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)1