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


##########
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();

Review Comment:
   [nit] authorResults instead of autorResults?



##########
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()

Review Comment:
   How do we handle cases where more than one `FacetBuilder` instances specify 
topN?



##########
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:
   To maintain output consistency between different examples, we could add 
something equivalent to what we have in `simpleFacetsWithSearch `? Or, we could 
remove it from there. 
   ```
   System.out.println(
           "Search results: totalHits: "
               + topDocs.totalHits
               + ", collected hits: "
               + topDocs.scoreDocs.length);
   ```
   



##########
lucene/sandbox/src/java/org/apache/lucene/sandbox/facet/utils/LongRangeFacetBuilder.java:
##########
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.sandbox.facet.utils;
+
+import org.apache.lucene.facet.MultiLongValuesSource;
+import org.apache.lucene.facet.range.LongRange;
+import org.apache.lucene.sandbox.facet.cutters.ranges.LongRangeFacetCutter;
+import org.apache.lucene.sandbox.facet.labels.RangeOrdToLabel;
+
+/** {@link FacetBuilder} factory for long range facets. */
+public final class LongRangeFacetBuilder {

Review Comment:
   Why don't we make `LongRangeFacetBuilder` extend `CommonFacetBuilder`? The 
`create` method returning something of a different type is a bit confusing to 
me.



##########
lucene/sandbox/src/java/org/apache/lucene/sandbox/facet/utils/CommonFacetBuilder.java:
##########
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.sandbox.facet.utils;
+
+import java.io.IOException;
+import org.apache.lucene.sandbox.facet.cutters.FacetCutter;
+import org.apache.lucene.sandbox.facet.labels.OrdToLabel;
+
+/**
+ * Common {@link FacetBuilder} that works with any {@link FacetCutter} and 
{@link OrdToLabel}
+ * provided by user.
+ */
+public final class CommonFacetBuilder extends 
BaseFacetBuilder<CommonFacetBuilder> {

Review Comment:
   I'm not sure when I should be using `CommonFacetBuilder ` vs 
`BaseFacetBuilder`? Some examples, even in the documentation would help? For 
e.g, why can't `TaxonomyFacetBuilder` extend `CommonFacetBuilder`?



##########
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

Review Comment:
   Thanks for creating the `FacetBuilder` and `FacetOrchestrator` abstractions 
- they do really simplify the usage of the new API. 



##########
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));
+
+    //// Build query and collect
+    DrillDownQuery query = new DrillDownQuery(config);
+    query.add("Author", "Lisa");
+
+    new DrillSidewaysFacetOrchestrator()
+        .addDrillDownBuilder(priceFacetBuilder)
+        .addDrillSidewaysBuilder("Author", authorFacetBuilder)
+        .collect(query, ds);
+
+    //// Results
+    FacetResult autorResults = authorFacetBuilder.getResult();

Review Comment:
   [nit] authorResults instead of autorResults?



-- 
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