Search in sources :

Example 16 with FacetResult

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

the class TestTaxonomyFacetCounts method testMultiValuedHierarchy.

public void testMultiValuedHierarchy() throws Exception {
    Directory dir = newDirectory();
    Directory taxoDir = newDirectory();
    DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);
    FacetsConfig config = new FacetsConfig();
    config.setHierarchical("a", true);
    config.setMultiValued("a", true);
    RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
    Document doc = new Document();
    doc.add(newTextField("field", "text", Field.Store.NO));
    doc.add(new FacetField("a", "path", "x"));
    doc.add(new FacetField("a", "path", "y"));
    writer.addDocument(config.build(taxoWriter, doc));
    // NRT open
    IndexSearcher searcher = newSearcher(writer.getReader());
    // NRT open
    TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoWriter);
    Facets facets = getAllFacets(FacetsConfig.DEFAULT_INDEX_FIELD_NAME, searcher, taxoReader, config);
    expectThrows(IllegalArgumentException.class, () -> {
        facets.getSpecificValue("a");
    });
    FacetResult result = facets.getTopChildren(10, "a");
    assertEquals(1, result.labelValues.length);
    assertEquals(1, result.labelValues[0].value.intValue());
    writer.close();
    IOUtils.close(taxoWriter, searcher.getIndexReader(), taxoReader, dir, taxoDir);
}
Also used : DirectoryTaxonomyWriter(org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter) IndexSearcher(org.apache.lucene.search.IndexSearcher) FacetsConfig(org.apache.lucene.facet.FacetsConfig) Facets(org.apache.lucene.facet.Facets) DirectoryTaxonomyReader(org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader) FacetField(org.apache.lucene.facet.FacetField) FacetResult(org.apache.lucene.facet.FacetResult) Document(org.apache.lucene.document.Document) RandomIndexWriter(org.apache.lucene.index.RandomIndexWriter) Directory(org.apache.lucene.store.Directory) DirectoryTaxonomyReader(org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader)

Example 17 with FacetResult

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

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

the class SimpleFacetsExample method main.

/** Runs the search and drill-down examples and prints the results. */
public static void main(String[] args) throws Exception {
    System.out.println("Facet counting example:");
    System.out.println("-----------------------");
    SimpleFacetsExample example = new SimpleFacetsExample();
    List<FacetResult> results1 = example.runFacetOnly();
    System.out.println("Author: " + results1.get(0));
    System.out.println("Publish Date: " + results1.get(1));
    System.out.println("Facet counting example (combined facets and search):");
    System.out.println("-----------------------");
    List<FacetResult> results = example.runSearch();
    System.out.println("Author: " + results.get(0));
    System.out.println("Publish Date: " + results.get(1));
    System.out.println("Facet drill-down example (Publish Date/2010):");
    System.out.println("---------------------------------------------");
    System.out.println("Author: " + example.runDrillDown());
    System.out.println("Facet drill-sideways example (Publish Date/2010):");
    System.out.println("---------------------------------------------");
    for (FacetResult result : example.runDrillSideways()) {
        System.out.println(result);
    }
}
Also used : FacetResult(org.apache.lucene.facet.FacetResult)

Example 19 with FacetResult

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

the class ExpressionAggregationFacetsExample method main.

/** Runs the search and drill-down examples and prints the results. */
public static void main(String[] args) throws Exception {
    System.out.println("Facet counting example:");
    System.out.println("-----------------------");
    FacetResult result = new ExpressionAggregationFacetsExample().runSearch();
    System.out.println(result);
}
Also used : FacetResult(org.apache.lucene.facet.FacetResult)

Example 20 with FacetResult

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

Aggregations

FacetResult (org.apache.lucene.facet.FacetResult)68 Facets (org.apache.lucene.facet.Facets)47 FacetsCollector (org.apache.lucene.facet.FacetsCollector)42 IndexSearcher (org.apache.lucene.search.IndexSearcher)36 DirectoryTaxonomyReader (org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader)29 LabelAndValue (org.apache.lucene.facet.LabelAndValue)28 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)23 DirectoryReader (org.apache.lucene.index.DirectoryReader)22 ArrayList (java.util.ArrayList)21 Directory (org.apache.lucene.store.Directory)21 FacetsConfig (org.apache.lucene.facet.FacetsConfig)19 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)19 Document (org.apache.lucene.document.Document)18 DirectoryTaxonomyWriter (org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter)14 DefaultSortedSetDocValuesReaderState (org.apache.lucene.facet.sortedset.DefaultSortedSetDocValuesReaderState)13 SortedSetDocValuesFacetCounts (org.apache.lucene.facet.sortedset.SortedSetDocValuesFacetCounts)13 SortedSetDocValuesReaderState (org.apache.lucene.facet.sortedset.SortedSetDocValuesReaderState)13 IOException (java.io.IOException)12 TaxonomyReader (org.apache.lucene.facet.taxonomy.TaxonomyReader)12 FacetField (org.apache.lucene.facet.FacetField)11