You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by gs...@apache.org on 2022/06/15 18:31:27 UTC

[lucene] branch main updated: LUCENE-10584: Properly support #getSpecificValue for hierarchical dims in SSDV faceting (#929)

This is an automated email from the ASF dual-hosted git repository.

gsmiller pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/lucene.git


The following commit(s) were added to refs/heads/main by this push:
     new 0b5e0bfa4f5 LUCENE-10584: Properly support #getSpecificValue for hierarchical dims in SSDV faceting (#929)
0b5e0bfa4f5 is described below

commit 0b5e0bfa4f5264b95113f2fe51e28a9bf4caa438
Author: Greg Miller <gs...@gmail.com>
AuthorDate: Wed Jun 15 11:31:23 2022 -0700

    LUCENE-10584: Properly support #getSpecificValue for hierarchical dims in SSDV faceting (#929)
---
 lucene/CHANGES.txt                                         |  3 +++
 .../sortedset/AbstractSortedSetDocValueFacetCounts.java    |  5 +++--
 .../facet/sortedset/TestSortedSetDocValuesFacets.java      | 14 ++++++++++++++
 3 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 4de5257f1ca..8d9c470678d 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -95,6 +95,9 @@ Bug Fixes
 
 * LUCENE-10574: Prevent pathological O(N^2) merging. (Adrien Grand)
 
+* LUCENE-10584: Properly support #getSpecificValue for hierarchical dims in SSDV faceting.
+  (Greg Miller)
+
 * LUCENE-10582: Fix merging of overridden CollectionStatistics in CombinedFieldQuery (Yannick Welsch)
 
 * LUCENE-10598: SortedSetDocValues#docValueCount() should be always greater than zero. (Lu Xugang)
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/sortedset/AbstractSortedSetDocValueFacetCounts.java b/lucene/facet/src/java/org/apache/lucene/facet/sortedset/AbstractSortedSetDocValueFacetCounts.java
index d0bbf7699bb..7edef89aca7 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/sortedset/AbstractSortedSetDocValueFacetCounts.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/sortedset/AbstractSortedSetDocValueFacetCounts.java
@@ -74,8 +74,9 @@ abstract class AbstractSortedSetDocValueFacetCounts extends Facets {
 
   @Override
   public Number getSpecificValue(String dim, String... path) throws IOException {
-    if (path.length != 1) {
-      throw new IllegalArgumentException("path must be length=1");
+    if (stateConfig.getDimConfig(dim).hierarchical == false && path.length != 1) {
+      throw new IllegalArgumentException(
+          dim + " is not configured as hierarchical, path must be length=1");
     }
     int ord = (int) dv.lookupTerm(new BytesRef(FacetsConfig.pathToString(dim, path)));
     if (ord < 0) {
diff --git a/lucene/facet/src/test/org/apache/lucene/facet/sortedset/TestSortedSetDocValuesFacets.java b/lucene/facet/src/test/org/apache/lucene/facet/sortedset/TestSortedSetDocValuesFacets.java
index 8b68db01db4..b893e3884fe 100644
--- a/lucene/facet/src/test/org/apache/lucene/facet/sortedset/TestSortedSetDocValuesFacets.java
+++ b/lucene/facet/src/test/org/apache/lucene/facet/sortedset/TestSortedSetDocValuesFacets.java
@@ -147,6 +147,11 @@ public class TestSortedSetDocValuesFacets extends FacetTestCase {
                 facets.getAllDims(0);
               });
 
+          // test getSpecificValue
+          assertEquals(2, facets.getSpecificValue("a", "foo"));
+          expectThrows(
+              IllegalArgumentException.class, () -> facets.getSpecificValue("a", "foo", "bar"));
+
           // DrillDown:
           DrillDownQuery q = new DrillDownQuery(config);
           q.add("a", "foo");
@@ -358,6 +363,15 @@ public class TestSortedSetDocValuesFacets extends FacetTestCase {
           assertEquals(
               "dim=c path=[buzz, bif] value=2 childCount=1\n  baf (2)\n",
               facets.getTopChildren(10, "c", "buzz", "bif").toString());
+
+          // test getSpecificValue (and make sure hierarchical dims are supported: LUCENE-10584):
+          assertEquals(2, facets.getSpecificValue("c", "buzz"));
+          // should be able to request deeper paths on hierarchical dims:
+          assertEquals(1, facets.getSpecificValue("c", "buzz", "bee"));
+          // ... but not on non-hierarchical dims:
+          expectThrows(
+              IllegalArgumentException.class, () -> facets.getSpecificValue("a", "foo", "bar)"));
+
           // DrillDown:
           DrillDownQuery q = new DrillDownQuery(config);
           q.add("a", "foo");