Search in sources :

Example 1 with TaxonomyFacetSumFloatAssociations

use of org.apache.lucene.facet.taxonomy.TaxonomyFacetSumFloatAssociations 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)

Example 2 with TaxonomyFacetSumFloatAssociations

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

the class AssociationsFacetsExample method drillDown.

/** User drills down on 'tags/solr'. */
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("tags", "solr");
    FacetsCollector fc = new FacetsCollector();
    FacetsCollector.search(searcher, q, 10, fc);
    // Retrieve results
    Facets facets = new TaxonomyFacetSumFloatAssociations("$genre", taxoReader, config, fc);
    FacetResult result = facets.getTopChildren(10, "genre");
    indexReader.close();
    taxoReader.close();
    return result;
}
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) DrillDownQuery(org.apache.lucene.facet.DrillDownQuery) FacetResult(org.apache.lucene.facet.FacetResult) TaxonomyFacetSumFloatAssociations(org.apache.lucene.facet.taxonomy.TaxonomyFacetSumFloatAssociations) DirectoryTaxonomyReader(org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader) FacetsCollector(org.apache.lucene.facet.FacetsCollector)

Aggregations

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