Skip to content

Apache Lucene open-source search software

LUCENE-10584: Properly support #getSpecificValue for hierarchical dims in SSDV faceting (#929)

Greg Miller0b5e0bfa4f52
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");