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/04/05 16:48:00 UTC
[lucene] branch branch_9x updated: LUCENE-10467: Throws IllegalArgumentException for getAllDims and getTopChildren if topN <= 0
This is an automated email from the ASF dual-hosted git repository.
gsmiller pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/lucene.git
The following commit(s) were added to refs/heads/branch_9x by this push:
new d1bd59f6bc6 LUCENE-10467: Throws IllegalArgumentException for getAllDims and getTopChildren if topN <= 0
d1bd59f6bc6 is described below
commit d1bd59f6bc6effe04f802e0d9a8f88fc7920f2cd
Author: Yuting Gan <44...@users.noreply.github.com>
AuthorDate: Tue Apr 5 09:28:59 2022 -0700
LUCENE-10467: Throws IllegalArgumentException for getAllDims and getTopChildren if topN <= 0
---
lucene/CHANGES.txt | 3 +++
.../src/java/org/apache/lucene/facet/Facets.java | 12 +++++++++
.../apache/lucene/facet/LongValueFacetCounts.java | 2 ++
.../java/org/apache/lucene/facet/MultiFacets.java | 3 ++-
.../lucene/facet/StringValueFacetCounts.java | 5 ++--
.../lucene/facet/range/RangeFacetCounts.java | 2 ++
.../ConcurrentSortedSetDocValuesFacetCounts.java | 7 ++---
.../sortedset/SortedSetDocValuesFacetCounts.java | 12 +++------
.../lucene/facet/taxonomy/FloatTaxonomyFacets.java | 4 +--
.../lucene/facet/taxonomy/IntTaxonomyFacets.java | 4 +--
.../lucene/facet/taxonomy/TaxonomyFacets.java | 1 +
.../org/apache/lucene/facet/TestDrillSideways.java | 30 ++++++++++++++++++++++
.../lucene/facet/TestLongValueFacetCounts.java | 6 +++++
.../lucene/facet/TestStringValueFacetCounts.java | 7 +++++
.../lucene/facet/range/TestRangeFacetCounts.java | 15 ++++++++++-
.../sortedset/TestSortedSetDocValuesFacets.java | 18 ++++++++++---
.../facet/taxonomy/TestTaxonomyFacetCounts.java | 25 ++++++++++++++++--
.../taxonomy/TestTaxonomyFacetSumValueSource.java | 20 ++++++++++-----
18 files changed, 141 insertions(+), 35 deletions(-)
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 49a65126d4a..1cb8b43a128 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -32,6 +32,9 @@ Improvements
* LUCENE-10484: Add support for concurrent random sampling by calling
RandomSamplingFacetsCollector#createManager. (Luca Cavanna)
+* LUCENE-10467: Throws IllegalArgumentException for Facets#getAllDims and Facets#getTopChildren
+ if topN <= 0. (Yuting Gan)
+
Optimizations
---------------------
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/Facets.java b/lucene/facet/src/java/org/apache/lucene/facet/Facets.java
index 1c7572d9443..7ceb02518a7 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/Facets.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/Facets.java
@@ -59,4 +59,16 @@ public abstract class Facets {
List<FacetResult> allResults = getAllDims(topNChildren);
return allResults.subList(0, Math.min(topNDims, allResults.size()));
}
+
+ /**
+ * This helper method checks if topN is valid for getTopChildren and getAllDims. Throws
+ * IllegalArgumentException if topN is invalid.
+ *
+ * @lucene.experimental it may not exist in future versions of Lucene
+ */
+ protected static void validateTopN(int topN) {
+ if (topN <= 0) {
+ throw new IllegalArgumentException("topN must be > 0 (got: " + topN + ")");
+ }
+ }
}
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/LongValueFacetCounts.java b/lucene/facet/src/java/org/apache/lucene/facet/LongValueFacetCounts.java
index defef4449bb..82bf7d65ac4 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/LongValueFacetCounts.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/LongValueFacetCounts.java
@@ -348,6 +348,7 @@ public class LongValueFacetCounts extends Facets {
@Override
public FacetResult getTopChildren(int topN, String dim, String... path) {
+ validateTopN(topN);
if (dim.equals(field) == false) {
throw new IllegalArgumentException(
"invalid dim \"" + dim + "\"; should be \"" + field + "\"");
@@ -489,6 +490,7 @@ public class LongValueFacetCounts extends Facets {
@Override
public List<FacetResult> getAllDims(int topN) {
+ validateTopN(topN);
return Collections.singletonList(getTopChildren(topN, field));
}
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/MultiFacets.java b/lucene/facet/src/java/org/apache/lucene/facet/MultiFacets.java
index e21fdc3e5d2..aa57013cada 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/MultiFacets.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/MultiFacets.java
@@ -42,6 +42,7 @@ public class MultiFacets extends Facets {
@Override
public FacetResult getTopChildren(int topN, String dim, String... path) throws IOException {
+ validateTopN(topN);
Facets facets = dimToFacets.get(dim);
if (facets == null) {
if (defaultFacets == null) {
@@ -66,7 +67,7 @@ public class MultiFacets extends Facets {
@Override
public List<FacetResult> getAllDims(int topN) throws IOException {
-
+ validateTopN(topN);
List<FacetResult> results = new ArrayList<FacetResult>();
// First add the specific dim's facets:
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/StringValueFacetCounts.java b/lucene/facet/src/java/org/apache/lucene/facet/StringValueFacetCounts.java
index 4d51fed475c..fdb8fd49a9b 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/StringValueFacetCounts.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/StringValueFacetCounts.java
@@ -132,9 +132,7 @@ public class StringValueFacetCounts extends Facets {
@Override
public FacetResult getTopChildren(int topN, String dim, String... path) throws IOException {
- if (topN <= 0) {
- throw new IllegalArgumentException("topN must be > 0 (got: " + topN + ")");
- }
+ validateTopN(topN);
if (dim.equals(field) == false) {
throw new IllegalArgumentException(
"invalid dim \"" + dim + "\"; should be \"" + field + "\"");
@@ -223,6 +221,7 @@ public class StringValueFacetCounts extends Facets {
@Override
public List<FacetResult> getAllDims(int topN) throws IOException {
+ validateTopN(topN);
return Collections.singletonList(getTopChildren(topN, field));
}
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/range/RangeFacetCounts.java b/lucene/facet/src/java/org/apache/lucene/facet/range/RangeFacetCounts.java
index fc376c5b0c7..3786fd089c2 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/range/RangeFacetCounts.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/range/RangeFacetCounts.java
@@ -218,6 +218,7 @@ abstract class RangeFacetCounts extends Facets {
@Override
public FacetResult getTopChildren(int topN, String dim, String... path) {
+ validateTopN(topN);
if (dim.equals(field) == false) {
throw new IllegalArgumentException(
"invalid dim \"" + dim + "\"; should be \"" + field + "\"");
@@ -240,6 +241,7 @@ abstract class RangeFacetCounts extends Facets {
@Override
public List<FacetResult> getAllDims(int topN) throws IOException {
+ validateTopN(topN);
return Collections.singletonList(getTopChildren(topN, field));
}
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/sortedset/ConcurrentSortedSetDocValuesFacetCounts.java b/lucene/facet/src/java/org/apache/lucene/facet/sortedset/ConcurrentSortedSetDocValuesFacetCounts.java
index 2e03579af5e..c1ce41533ea 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/sortedset/ConcurrentSortedSetDocValuesFacetCounts.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/sortedset/ConcurrentSortedSetDocValuesFacetCounts.java
@@ -99,10 +99,7 @@ public class ConcurrentSortedSetDocValuesFacetCounts extends Facets {
@Override
public FacetResult getTopChildren(int topN, String dim, String... path) throws IOException {
- if (topN <= 0) {
- throw new IllegalArgumentException("topN must be > 0 (got: " + topN + ")");
- }
-
+ validateTopN(topN);
FacetsConfig.DimConfig dimConfig = stateConfig.getDimConfig(dim);
if (dimConfig.hierarchical) {
@@ -412,7 +409,7 @@ public class ConcurrentSortedSetDocValuesFacetCounts extends Facets {
@Override
public List<FacetResult> getAllDims(int topN) throws IOException {
-
+ validateTopN(topN);
List<FacetResult> results = new ArrayList<>();
for (String dim : state.getDims()) {
FacetsConfig.DimConfig dimConfig = stateConfig.getDimConfig(dim);
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/sortedset/SortedSetDocValuesFacetCounts.java b/lucene/facet/src/java/org/apache/lucene/facet/sortedset/SortedSetDocValuesFacetCounts.java
index 17018ddd927..c0f3daecc1e 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/sortedset/SortedSetDocValuesFacetCounts.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/sortedset/SortedSetDocValuesFacetCounts.java
@@ -104,10 +104,7 @@ public class SortedSetDocValuesFacetCounts extends Facets {
@Override
public FacetResult getTopChildren(int topN, String dim, String... path) throws IOException {
- if (topN <= 0) {
- throw new IllegalArgumentException("topN must be > 0 (got: " + topN + ")");
- }
-
+ validateTopN(topN);
FacetsConfig.DimConfig dimConfig = stateConfig.getDimConfig(dim);
if (dimConfig.hierarchical) {
@@ -198,7 +195,6 @@ public class SortedSetDocValuesFacetCounts extends Facets {
*/
private ChildOrdsResult getChildOrdsResult(
PrimitiveIterator.OfInt childOrds, int topN, FacetsConfig.DimConfig dimConfig, int pathOrd) {
-
TopOrdAndIntQueue q = null;
int bottomCount = 0;
int dimCount = 0;
@@ -485,6 +481,7 @@ public class SortedSetDocValuesFacetCounts extends Facets {
@Override
public List<FacetResult> getAllDims(int topN) throws IOException {
+ validateTopN(topN);
List<FacetResult> results = new ArrayList<>();
for (String dim : state.getDims()) {
FacetResult factResult = getFacetResultForDim(dim, topN);
@@ -513,9 +510,8 @@ public class SortedSetDocValuesFacetCounts extends Facets {
@Override
public List<FacetResult> getTopDims(int topNDims, int topNChildren) throws IOException {
- if (topNDims <= 0 || topNChildren <= 0) {
- throw new IllegalArgumentException("topN must be > 0");
- }
+ validateTopN(topNDims);
+ validateTopN(topNChildren);
// Creates priority queue to store top dimensions and sort by their aggregated values/hits and
// string values.
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/FloatTaxonomyFacets.java b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/FloatTaxonomyFacets.java
index 902f8cd530c..8d874c684bd 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/FloatTaxonomyFacets.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/FloatTaxonomyFacets.java
@@ -98,9 +98,7 @@ public abstract class FloatTaxonomyFacets extends TaxonomyFacets {
@Override
public FacetResult getTopChildren(int topN, String dim, String... path) throws IOException {
- if (topN <= 0) {
- throw new IllegalArgumentException("topN must be > 0 (got: " + topN + ")");
- }
+ validateTopN(topN);
DimConfig dimConfig = verifyDim(dim);
FacetLabel cp = new FacetLabel(dim, path);
int dimOrd = taxoReader.getOrdinal(cp);
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/IntTaxonomyFacets.java b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/IntTaxonomyFacets.java
index afc5fb1915c..99757d76eb0 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/IntTaxonomyFacets.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/IntTaxonomyFacets.java
@@ -173,9 +173,7 @@ public abstract class IntTaxonomyFacets extends TaxonomyFacets {
@Override
public FacetResult getTopChildren(int topN, String dim, String... path) throws IOException {
- if (topN <= 0) {
- throw new IllegalArgumentException("topN must be > 0 (got: " + topN + ")");
- }
+ validateTopN(topN);
DimConfig dimConfig = verifyDim(dim);
FacetLabel cp = new FacetLabel(dim, path);
int dimOrd = taxoReader.getOrdinal(cp);
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/TaxonomyFacets.java b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/TaxonomyFacets.java
index 4d444052707..3a437e94d03 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/TaxonomyFacets.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/TaxonomyFacets.java
@@ -147,6 +147,7 @@ public abstract class TaxonomyFacets extends Facets {
@Override
public List<FacetResult> getAllDims(int topN) throws IOException {
+ validateTopN(topN);
int[] children = getChildren();
int[] siblings = getSiblings();
int ord = children[TaxonomyReader.ROOT_ORDINAL];
diff --git a/lucene/facet/src/test/org/apache/lucene/facet/TestDrillSideways.java b/lucene/facet/src/test/org/apache/lucene/facet/TestDrillSideways.java
index 1fe741466e6..e68be0f5975 100644
--- a/lucene/facet/src/test/org/apache/lucene/facet/TestDrillSideways.java
+++ b/lucene/facet/src/test/org/apache/lucene/facet/TestDrillSideways.java
@@ -234,6 +234,13 @@ public class TestDrillSideways extends FacetTestCase {
"dim=Size path=[] value=2 childCount=2\n Small (1)\n Medium (1)\n",
concurrentResult.facets.getTopChildren(10, "Size").toString());
+ // test getTopChildren(0, dim)
+ expectThrows(
+ IllegalArgumentException.class,
+ () -> {
+ concurrentResult.facets.getTopChildren(0, "Color");
+ });
+
writer.close();
IOUtils.close(searcher.getIndexReader(), taxoReader, taxoWriter, dir, taxoDir);
}
@@ -371,6 +378,14 @@ public class TestDrillSideways extends FacetTestCase {
List<FacetResult> topDimsResults2 = r.facets.getTopDims(0, 1);
assertEquals(0, topDimsResults2.size());
+ // test getAllDims(0)
+ DrillSidewaysResult finalR1 = r;
+ expectThrows(
+ IllegalArgumentException.class,
+ () -> {
+ finalR1.facets.getAllDims(0);
+ });
+
// More interesting case: drill-down on two fields
ddq = new DrillDownQuery(config);
ddq.add("Author", "Lisa");
@@ -456,6 +471,15 @@ public class TestDrillSideways extends FacetTestCase {
assertEquals(0, r.hits.totalHits.value);
assertNull(r.facets.getTopChildren(10, "Publish Date"));
assertNull(r.facets.getTopChildren(10, "Author"));
+
+ // test getTopChildren(0, dim)
+ DrillSidewaysResult finalR = r;
+ expectThrows(
+ IllegalArgumentException.class,
+ () -> {
+ finalR.facets.getTopChildren(0, "Author");
+ });
+
writer.close();
IOUtils.close(searcher.getIndexReader(), taxoReader, taxoWriter, dir, taxoDir);
}
@@ -1874,6 +1898,12 @@ public class TestDrillSideways extends FacetTestCase {
"dim=Author path=[] value=5 childCount=4\n Lisa (2)\n Susan (1)\n",
topNDimsResult.get(0).toString());
+ // test getAllDims(0)
+ expectThrows(
+ IllegalArgumentException.class,
+ () -> {
+ facets.getAllDims(0);
+ });
// More interesting case: drill-down on two fields
ddq = new DrillDownQuery(config);
ddq.add("Author", "Lisa");
diff --git a/lucene/facet/src/test/org/apache/lucene/facet/TestLongValueFacetCounts.java b/lucene/facet/src/test/org/apache/lucene/facet/TestLongValueFacetCounts.java
index ad0cd847891..eaf8d64634c 100644
--- a/lucene/facet/src/test/org/apache/lucene/facet/TestLongValueFacetCounts.java
+++ b/lucene/facet/src/test/org/apache/lucene/facet/TestLongValueFacetCounts.java
@@ -166,6 +166,12 @@ public class TestLongValueFacetCounts extends LuceneTestCase {
// test getTopDims(0, 1)
List<FacetResult> topDimsResults2 = facets.getTopDims(0, 1);
assertEquals(0, topDimsResults2.size());
+ // test getAllDims(0)
+ expectThrows(
+ IllegalArgumentException.class,
+ () -> {
+ facets.getAllDims(0);
+ });
r.close();
d.close();
diff --git a/lucene/facet/src/test/org/apache/lucene/facet/TestStringValueFacetCounts.java b/lucene/facet/src/test/org/apache/lucene/facet/TestStringValueFacetCounts.java
index b8d2abf9b85..ed0716201fd 100644
--- a/lucene/facet/src/test/org/apache/lucene/facet/TestStringValueFacetCounts.java
+++ b/lucene/facet/src/test/org/apache/lucene/facet/TestStringValueFacetCounts.java
@@ -390,6 +390,13 @@ public class TestStringValueFacetCounts extends FacetTestCase {
assertEquals(1, topNDimsResult.size());
assertEquals(facetResult, topNDimsResult.get(0));
+ // test getAllDims(0)
+ expectThrows(
+ IllegalArgumentException.class,
+ () -> {
+ facets.getAllDims(0);
+ });
+
// This is a little strange, but we request all labels at this point so that when we
// secondarily sort by label value in order to compare to the expected results, we have
// all the values. See LUCENE-9991:
diff --git a/lucene/facet/src/test/org/apache/lucene/facet/range/TestRangeFacetCounts.java b/lucene/facet/src/test/org/apache/lucene/facet/range/TestRangeFacetCounts.java
index d807c23ec76..cdfdefd539b 100644
--- a/lucene/facet/src/test/org/apache/lucene/facet/range/TestRangeFacetCounts.java
+++ b/lucene/facet/src/test/org/apache/lucene/facet/range/TestRangeFacetCounts.java
@@ -104,6 +104,13 @@ public class TestRangeFacetCounts extends FacetTestCase {
"dim=field path=[] value=22 childCount=5\n less than 10 (10)\n less than or equal to 10 (11)\n over 90 (9)\n 90 or above (10)\n over 1000 (1)\n",
result.toString());
+ // test getTopChildren(0, dim)
+ expectThrows(
+ IllegalArgumentException.class,
+ () -> {
+ facets.getTopChildren(0, "field");
+ });
+
r.close();
d.close();
}
@@ -255,6 +262,13 @@ public class TestRangeFacetCounts extends FacetTestCase {
List<FacetResult> topDimsResults2 = facets.getTopDims(0, 1);
assertEquals(0, topDimsResults2.size());
+ // test getAllDims(0)
+ expectThrows(
+ IllegalArgumentException.class,
+ () -> {
+ facets.getAllDims(0);
+ });
+
r.close();
d.close();
}
@@ -354,7 +368,6 @@ public class TestRangeFacetCounts extends FacetTestCase {
assertEquals(
"dim=field path=[] value=41 childCount=4\n 0-10 (11)\n 10-20 (11)\n 20-30 (11)\n 30-40 (11)\n",
result.toString());
-
r.close();
d.close();
}
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 587fe24328b..80499b3d0f8 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
@@ -140,6 +140,13 @@ public class TestSortedSetDocValuesFacets extends FacetTestCase {
"dim=b path=[] value=2 childCount=2\n buzz (2)\n",
topDimsResults1.get(0).toString());
+ // test getTopDims(0)
+ expectThrows(
+ IllegalArgumentException.class,
+ () -> {
+ facets.getAllDims(0);
+ });
+
// DrillDown:
DrillDownQuery q = new DrillDownQuery(config);
q.add("a", "foo");
@@ -351,7 +358,6 @@ 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());
-
// DrillDown:
DrillDownQuery q = new DrillDownQuery(config);
q.add("a", "foo");
@@ -407,6 +413,14 @@ public class TestSortedSetDocValuesFacets extends FacetTestCase {
"dim=a path=[] value=1 childCount=1\n bar (1)\n",
facets.getTopChildren(10, "a").toString());
+ // test topNChildren = 0
+ Facets finalFacets = facets;
+ expectThrows(
+ IllegalArgumentException.class,
+ () -> {
+ finalFacets.getTopChildren(0, "a");
+ });
+
ExecutorService exec =
new ThreadPoolExecutor(
1,
@@ -464,7 +478,6 @@ public class TestSortedSetDocValuesFacets extends FacetTestCase {
assertEquals(
"dim=b path=[buzz] value=1 childCount=1\n baz (1)\n",
facets.getTopChildren(10, "b", "buzz").toString());
-
ExecutorService exec =
new ThreadPoolExecutor(
1,
@@ -1231,7 +1244,6 @@ public class TestSortedSetDocValuesFacets extends FacetTestCase {
sortFacetResults(expected);
List<FacetResult> actual = facets.getAllDims(10);
-
// Messy: fixup ties
// sortTies(actual);
diff --git a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetCounts.java b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetCounts.java
index f0de3871046..954aae3b3fa 100644
--- a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetCounts.java
+++ b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetCounts.java
@@ -112,6 +112,14 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {
assertTrue(((TaxonomyFacets) facets).siblingsLoaded());
assertTrue(((TaxonomyFacets) facets).childrenLoaded());
+ // test getTopChildren(0, dim)
+ Facets finalFacets = facets;
+ expectThrows(
+ IllegalArgumentException.class,
+ () -> {
+ finalFacets.getTopChildren(0, "Author");
+ });
+
// Retrieve & verify results:
assertEquals(
"dim=Publish Date path=[] value=5 childCount=3\n 2010 (2)\n 2012 (2)\n 1999 (1)\n",
@@ -194,6 +202,13 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {
Facets facets =
getAllFacets(FacetsConfig.DEFAULT_INDEX_FIELD_NAME, searcher, taxoReader, config);
+ // test getAllDims(0)
+ expectThrows(
+ IllegalArgumentException.class,
+ () -> {
+ facets.getAllDims(0);
+ });
+
// Ask for top 10 labels for any dims that have counts:
List<FacetResult> results = facets.getAllDims(10);
@@ -281,7 +296,6 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {
// Ask for top 10 labels for any dims that have counts:
List<FacetResult> results = facets.getAllDims(10);
assertTrue(results.isEmpty());
-
expectThrows(
IllegalArgumentException.class,
() -> {
@@ -477,6 +491,7 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {
() -> {
facets.getSpecificValue("dim");
});
+
assertEquals(1, facets.getSpecificValue("dim2"));
assertEquals(1, facets.getSpecificValue("dim3"));
writer.close();
@@ -653,6 +668,13 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {
facets.getTopDims(1, 0);
});
+ // test getAllDims(0)
+ expectThrows(
+ IllegalArgumentException.class,
+ () -> {
+ facets.getAllDims(0);
+ });
+
iw.close();
IOUtils.close(taxoWriter, taxoReader, taxoDir, r, indexDir);
}
@@ -867,7 +889,6 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {
sortFacetResults(expected);
List<FacetResult> actual = facets.getAllDims(10);
-
// Messy: fixup ties
sortTies(actual);
diff --git a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetSumValueSource.java b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetSumValueSource.java
index 03c27301c11..bd23587f237 100644
--- a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetSumValueSource.java
+++ b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetSumValueSource.java
@@ -120,6 +120,13 @@ public class TestTaxonomyFacetSumValueSource extends FacetTestCase {
"dim=Author path=[] value=145.0 childCount=4\n Lisa (50.0)\n Frank (45.0)\n Susan (40.0)\n Bob (10.0)\n",
facets.getTopChildren(10, "Author").toString());
+ // test getTopChildren(0, dim)
+ expectThrows(
+ IllegalArgumentException.class,
+ () -> {
+ facets.getTopChildren(0, "Author");
+ });
+
taxoReader.close();
searcher.getIndexReader().close();
dir.close();
@@ -182,6 +189,13 @@ public class TestTaxonomyFacetSumValueSource extends FacetTestCase {
// Ask for top 10 labels for any dims that have counts:
List<FacetResult> results = facets.getAllDims(10);
+ // test getAllDims(0)
+ expectThrows(
+ IllegalArgumentException.class,
+ () -> {
+ facets.getAllDims(0);
+ });
+
assertEquals(3, results.size());
assertEquals(
"dim=a path=[] value=60.0 childCount=3\n foo3 (30.0)\n foo2 (20.0)\n foo1 (10.0)\n",
@@ -259,7 +273,6 @@ public class TestTaxonomyFacetSumValueSource extends FacetTestCase {
// test default implementation of getTopDims
List<FacetResult> topDimsResults = facets.getTopDims(10, 10);
assertTrue(topDimsResults.isEmpty());
-
expectThrows(
IllegalArgumentException.class,
() -> {
@@ -336,7 +349,6 @@ public class TestTaxonomyFacetSumValueSource extends FacetTestCase {
assertEquals(
"dim=a path=[] value=10.0 childCount=2\n 1 (6.0)\n 0 (4.0)\n",
facets.getTopChildren(10, "a").toString());
-
iw.close();
IOUtils.close(taxoWriter, taxoReader, taxoDir, r, indexDir);
}
@@ -375,7 +387,6 @@ public class TestTaxonomyFacetSumValueSource extends FacetTestCase {
assertEquals(
"dim=a path=[] value=10.0 childCount=2\n 1 (6.0)\n 0 (4.0)\n",
facets.getTopChildren(10, "a").toString());
-
iw.close();
IOUtils.close(taxoWriter, taxoReader, taxoDir, r, indexDir);
}
@@ -409,7 +420,6 @@ public class TestTaxonomyFacetSumValueSource extends FacetTestCase {
assertEquals(
"dim=a path=[] value=10.0 childCount=2\n 1 (6.0)\n 0 (4.0)\n",
facets.getTopChildren(10, "a").toString());
-
iw.close();
IOUtils.close(taxoWriter, taxoReader, taxoDir, r, indexDir);
}
@@ -544,13 +554,11 @@ public class TestTaxonomyFacetSumValueSource extends FacetTestCase {
sortFacetResults(expected);
List<FacetResult> actual = facets.getAllDims(10);
-
// test default implementation of getTopDims
if (actual.size() > 0) {
List<FacetResult> topDimsResults1 = facets.getTopDims(1, 10);
assertEquals(actual.get(0), topDimsResults1.get(0));
}
-
// Messy: fixup ties
sortTies(actual);