mikemccand commented on a change in pull request #25:
URL: https://github.com/apache/lucene/pull/25#discussion_r599557787



##########
File path: lucene/facet/src/java/org/apache/lucene/facet/FacetsConfig.java
##########
@@ -388,6 +434,26 @@ private void processFacetFields(
     }
   }
 
+  private void indexDrillDownTerms(
+      Document doc, String indexFieldName, DimConfig ft, FacetLabel cp) {
+    if (ft.drillDownTermsIndexing != DrillDownTermsIndexing.NONE) {
+      doc.add(
+          new StringField(indexFieldName, pathToString(cp.components, 
cp.length), Field.Store.NO));
+
+      if (ft.drillDownTermsIndexing == 
DrillDownTermsIndexing.DIMENSION_AND_FULL_PATH) {
+        doc.add(new StringField(indexFieldName, pathToString(cp.components, 
1), Field.Store.NO));
+      } else if (ft.drillDownTermsIndexing == 
DrillDownTermsIndexing.ALL_PATHS_NO_DIM) {
+        for (int i = 2; i < cp.length; i++) {
+          doc.add(new StringField(indexFieldName, pathToString(cp.components, 
i), Field.Store.NO));
+        }
+      } else if (ft.drillDownTermsIndexing == DrillDownTermsIndexing.ALL) {
+        for (int i = 1; i < cp.length; i++) {
+          doc.add(new StringField(indexFieldName, pathToString(cp.components, 
i), Field.Store.NO));
+        }
+      }

Review comment:
       Maybe insert `} else { throw AssertionError(...)` to catch future 
accident of adding a new `enum` value and failing to fix this tricky code?
   
   If we switch to `switch` you could add a `default` case and `throw` there.

##########
File path: lucene/facet/src/java/org/apache/lucene/facet/FacetsConfig.java
##########
@@ -408,7 +475,7 @@ private void processSSDVFacetFields(
         doc.add(new StringField(indexFieldName, fullPath, Field.Store.NO));

Review comment:
       Indeed, this is a weird forced-fit: SSDV facets are not hierarchical, or 
rather, they have only `dim` and `label`.
   
   But I think all of the new `enum` options can be implemented correctly here, 
as if this were a taxonomy facets field of depth two (`a/b`)?

##########
File path: lucene/facet/src/java/org/apache/lucene/facet/FacetsConfig.java
##########
@@ -388,6 +434,26 @@ private void processFacetFields(
     }
   }
 
+  private void indexDrillDownTerms(
+      Document doc, String indexFieldName, DimConfig ft, FacetLabel cp) {
+    if (ft.drillDownTermsIndexing != DrillDownTermsIndexing.NONE) {
+      doc.add(

Review comment:
       Could you add a comment above this e.g. `// index full-path token` or so?

##########
File path: lucene/facet/src/test/org/apache/lucene/facet/TestDrillDownQuery.java
##########
@@ -299,4 +300,233 @@ public void testRequireDimensionDrillDown() throws 
Exception {
     assertEquals(0, searcher.count(q));
     IOUtils.close(taxoReader, reader, writer, dir, taxoDir);
   }
+
+  public void testSkipDrillDownTermsIndexing() throws Exception {
+    Directory dir = newDirectory();
+    RandomIndexWriter writer =
+        new RandomIndexWriter(
+            random(),
+            dir,
+            newIndexWriterConfig(new MockAnalyzer(random(), 
MockTokenizer.KEYWORD, false)));
+    Directory taxoDir = newDirectory();
+    TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);
+    FacetsConfig config = new FacetsConfig();
+    config.setDrillDownTermsIndexing("a", 
FacetsConfig.DrillDownTermsIndexing.FULL_PATH_ONLY);
+    config.setDrillDownTermsIndexing("b", 
FacetsConfig.DrillDownTermsIndexing.FULL_PATH_ONLY);
+
+    Document doc = new Document();
+    doc.add(new FacetField("a", "1"));
+    doc.add(new FacetField("b", "2"));
+    writer.addDocument(config.build(taxoWriter, doc));
+    taxoWriter.close();
+
+    IndexReader reader = writer.getReader();
+    DirectoryTaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);
+    IndexSearcher searcher = newSearcher(reader);
+
+    DrillDownQuery q = new DrillDownQuery(config);
+    q.add("a");
+    // no hits because we disabled dimension drill down completely
+    assertEquals(0, searcher.count(q));
+
+    q = new DrillDownQuery(config);
+    q.add("a", "1");
+    assertEquals(1, searcher.count(q));
+
+    q = new DrillDownQuery(config);
+    q.add("b");
+    // no hits because we disabled dimension drill down completely
+    assertEquals(0, searcher.count(q));
+
+    q = new DrillDownQuery(config);
+    q.add("b", "2");
+    assertEquals(1, searcher.count(q));
+
+    IOUtils.close(taxoReader, reader, writer, dir, taxoDir);
+  }
+
+  public void testDrillDownTermsDifferentOptions() throws Exception {
+    Directory dir = newDirectory();
+    RandomIndexWriter writer =
+        new RandomIndexWriter(
+            random(),
+            dir,
+            newIndexWriterConfig(new MockAnalyzer(random(), 
MockTokenizer.KEYWORD, false)));
+    Directory taxoDir = newDirectory();
+    TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);
+    FacetsConfig config = new FacetsConfig();
+    config.setHierarchical("a", true);
+    config.setHierarchical("b", true);
+    config.setHierarchical("c", true);
+    config.setHierarchical("d", true);
+    config.setHierarchical("e", true);
+    config.setDrillDownTermsIndexing("a", 
FacetsConfig.DrillDownTermsIndexing.NONE);
+    config.setDrillDownTermsIndexing("b", 
FacetsConfig.DrillDownTermsIndexing.FULL_PATH_ONLY);
+    config.setDrillDownTermsIndexing("c", 
FacetsConfig.DrillDownTermsIndexing.ALL_PATHS_NO_DIM);
+    config.setDrillDownTermsIndexing(
+        "d", FacetsConfig.DrillDownTermsIndexing.DIMENSION_AND_FULL_PATH);
+    config.setDrillDownTermsIndexing("e", 
FacetsConfig.DrillDownTermsIndexing.ALL);
+    config.setDrillDownTermsIndexing("f", 
FacetsConfig.DrillDownTermsIndexing.NONE);
+    config.setIndexFieldName("f", "facet-for-f");
+
+    Document doc = new Document();
+    doc.add(new FacetField("a", "a1", "a2", "a3"));
+    doc.add(new FacetField("b", "b1", "b2", "b3"));
+    doc.add(new FacetField("c", "c1", "c2", "c3"));
+    doc.add(new FacetField("d", "d1", "d2", "d3"));
+    doc.add(new FacetField("e", "e1", "e2", "e3"));
+    doc.add(new IntAssociationFacetField(5, "f", "f1"));
+    writer.addDocument(config.build(taxoWriter, doc));
+    taxoWriter.close();
+
+    IndexReader reader = writer.getReader();
+    DirectoryTaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);
+    IndexSearcher searcher = newSearcher(reader);
+
+    // Verifies for FacetsConfig.DrillDownTermsIndexing.NONE option
+    DrillDownQuery q = new DrillDownQuery(config);
+    q.add("a");
+    assertEquals(0, searcher.count(q));
+
+    q = new DrillDownQuery(config);
+    q.add("a", "a1");
+    assertEquals(0, searcher.count(q));
+
+    q = new DrillDownQuery(config);
+    q.add("a", "a1", "a2");
+    assertEquals(0, searcher.count(q));
+
+    q = new DrillDownQuery(config);
+    q.add("a", "a1", "a2", "a3");
+    assertEquals(0, searcher.count(q));
+
+    // Verifies for FacetsConfig.DrillDownTermsIndexing.FULL_PATH_ONLY option
+    q = new DrillDownQuery(config);
+    q.add("b");
+    assertEquals(0, searcher.count(q));
+
+    q = new DrillDownQuery(config);
+    q.add("b", "b1");
+    assertEquals(0, searcher.count(q));
+
+    q = new DrillDownQuery(config);
+    q.add("b", "b1", "b2");
+    assertEquals(0, searcher.count(q));
+
+    q = new DrillDownQuery(config);
+    q.add("b", "b1", "b2", "b3");
+    assertEquals(1, searcher.count(q));
+
+    // Verifies for FacetsConfig.DrillDownTermsIndexing.ALL_PATHS_NO_DIM option
+    q = new DrillDownQuery(config);
+    q.add("c");
+    assertEquals(0, searcher.count(q));
+
+    q = new DrillDownQuery(config);
+    q.add("c", "c1");
+    assertEquals(1, searcher.count(q));
+
+    q = new DrillDownQuery(config);
+    q.add("c", "c1", "c2");
+    assertEquals(1, searcher.count(q));
+
+    q = new DrillDownQuery(config);
+    q.add("c", "c1", "c2", "c3");
+    assertEquals(1, searcher.count(q));
+
+    // Verifies for 
FacetsConfig.DrillDownTermsIndexing.DIMENSION_AND_FULL_PATH option
+    q = new DrillDownQuery(config);
+    q.add("d");
+    assertEquals(1, searcher.count(q));
+
+    q = new DrillDownQuery(config);
+    q.add("d", "d1");
+    assertEquals(0, searcher.count(q));
+
+    q = new DrillDownQuery(config);
+    q.add("d", "d1", "d2");
+    assertEquals(0, searcher.count(q));
+
+    q = new DrillDownQuery(config);
+    q.add("d", "d1", "d2", "d3");
+    assertEquals(1, searcher.count(q));
+
+    // Verifies for FacetsConfig.DrillDownTermsIndexing.ALL option
+    q = new DrillDownQuery(config);
+    q.add("e");
+    assertEquals(1, searcher.count(q));
+
+    q = new DrillDownQuery(config);
+    q.add("e", "e1");
+    assertEquals(1, searcher.count(q));
+
+    q = new DrillDownQuery(config);
+    q.add("e", "e1", "e2");
+    assertEquals(1, searcher.count(q));
+
+    q = new DrillDownQuery(config);
+    q.add("e", "e1", "e2", "e3");
+    assertEquals(1, searcher.count(q));
+
+    // Verifies for 
FacetsConfig.DrillDownTermsIndexing.DIMENSION_AND_FULL_PATH option with
+    // IntAssociationFacetField
+    q = new DrillDownQuery(config);
+    q.add("f");
+    assertEquals(0, searcher.count(q));
+
+    q = new DrillDownQuery(config);
+    q.add("f", "f1");
+    assertEquals(0, searcher.count(q));
+
+    IOUtils.close(taxoReader, reader, writer, dir, taxoDir);
+  }
+
+  public void testDrillDownTermsDefaultWithHierarchicalSetting() throws 
Exception {

Review comment:
       Thank you @zacharymorn for the added test cases!

##########
File path: lucene/facet/src/java/org/apache/lucene/facet/FacetsConfig.java
##########
@@ -168,14 +203,34 @@ public synchronized void setIndexFieldName(String 
dimName, String indexFieldName
     ft.indexFieldName = indexFieldName;
   }
 
-  /** Specify whether drill down on just the dimension is necessary. */
+  /**
+   * Specify whether drill down on the dimension is necessary.
+   *
+   * @deprecated Use {@link FacetsConfig#setDrillDownTermsIndexing(String, 
DrillDownTermsIndexing)}
+   *     instead
+   */
+  @Deprecated
   public synchronized void setRequireDimensionDrillDown(String dimName, 
boolean v) {

Review comment:
       We should have full backwards compatibility with this, right?  In which 
case we could backport this change to 8.x too!

##########
File path: lucene/facet/src/java/org/apache/lucene/facet/FacetsConfig.java
##########
@@ -388,6 +434,26 @@ private void processFacetFields(
     }
   }
 
+  private void indexDrillDownTerms(
+      Document doc, String indexFieldName, DimConfig ft, FacetLabel cp) {
+    if (ft.drillDownTermsIndexing != DrillDownTermsIndexing.NONE) {

Review comment:
       Maybe, keep the outer `if` checking for `not NONE`, but and then add the 
full-path term here, but then switch to `switch` for the inner three cases?




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

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to