epotyom commented on code in PR #14237:
URL: https://github.com/apache/lucene/pull/14237#discussion_r1960058010


##########
lucene/demo/src/java/org/apache/lucene/demo/facet/SandboxFacetsExample.java:
##########
@@ -130,6 +135,88 @@ void index() throws IOException {
     IOUtils.close(indexWriter, taxoWriter);
   }
 
+  /**
+   * Example for {@link FacetBuilder} usage - simple API that provides results 
in a format very
+   * similar to classic facets module. It doesn't give all flexibility 
available with {@link
+   * org.apache.lucene.sandbox.facet.cutters.FacetCutter} and {@link
+   * org.apache.lucene.sandbox.facet.recorders.FacetRecorder} though, see 
below for lower level API
+   * usage examples.
+   */
+  private List<FacetResult> simpleFacetsWithSearch() throws IOException {
+    //// init readers and searcher
+    DirectoryReader indexReader = DirectoryReader.open(indexDir);
+    IndexSearcher searcher = new IndexSearcher(indexReader);
+    TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);
+
+    //// build facets requests
+    FacetBuilder authorFacetBuilder =
+        new TaxonomyFacetBuilder(config, taxoReader, "Author").withTopN(10);
+    FacetBuilder priceFacetBuilder =
+        LongRangeFacetBuilder.create(
+            "Price",
+            new LongRange("0-10", 0, true, 10, true),
+            new LongRange("10-20", 10, true, 20, true));
+
+    //// Main hits collector
+    TopScoreDocCollectorManager hitsCollectorManager =
+        new TopScoreDocCollectorManager(2, Integer.MAX_VALUE);
+
+    //// Search and collect
+    TopDocs topDocs =
+        new FacetOrchestrator()
+            .addBuilder(authorFacetBuilder)
+            .addBuilder(priceFacetBuilder)
+            .collect(new MatchAllDocsQuery(), searcher, hitsCollectorManager);
+    System.out.println(
+        "Search results: totalHits: "
+            + topDocs.totalHits
+            + ", collected hits: "
+            + topDocs.scoreDocs.length);
+
+    //// Results
+    FacetResult autorResults = authorFacetBuilder.getResult();
+    FacetResult rangeResults = priceFacetBuilder.getResult();
+
+    IOUtils.close(indexReader, taxoReader);
+
+    return List.of(autorResults, rangeResults);
+  }
+
+  /** Example for {@link FacetBuilder} usage with {@link DrillSideways}. */
+  private List<FacetResult> simpleFacetsWithDrillSideways() throws IOException 
{
+    //// init readers and searcher
+    DirectoryReader indexReader = DirectoryReader.open(indexDir);
+    IndexSearcher searcher = new IndexSearcher(indexReader);
+    TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);
+    DrillSideways ds = new DrillSideways(searcher, config, taxoReader);
+
+    //// build facets requests
+    FacetBuilder authorFacetBuilder =
+        new TaxonomyFacetBuilder(config, taxoReader, "Author").withTopN(10);
+    FacetBuilder priceFacetBuilder =
+        LongRangeFacetBuilder.create(
+            "Price",
+            new LongRange("0-10", 0, true, 10, true),
+            new LongRange("10-20", 10, true, 20, true));
+

Review Comment:
   I did this intentionally, to demonstrate that there are methods to do facet 
only and facets with search (examples that have`WithSearch` suffix also 
compute/print TopDocs). We can rename this example to 
`simpleFacetsOnlyWithDrillSideways` maybe?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to