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

This commit is contained in:
Greg Miller 2022-06-15 11:31:23 -07:00 committed by GitHub
parent d52122605d
commit 0b5e0bfa4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 2 deletions

View File

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

View File

@ -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) {

View File

@ -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");