diff --git a/lucene/facet/src/java/org/apache/lucene/facet/hyperrectangle/DoubleHyperRectangle.java b/lucene/facet/src/java/org/apache/lucene/facet/hyperrectangle/DoubleHyperRectangle.java index e1db9cb250d3..1b61d75dd7ad 100644 --- a/lucene/facet/src/java/org/apache/lucene/facet/hyperrectangle/DoubleHyperRectangle.java +++ b/lucene/facet/src/java/org/apache/lucene/facet/hyperrectangle/DoubleHyperRectangle.java @@ -24,10 +24,10 @@ public class DoubleHyperRectangle extends HyperRectangle { /** Creates DoubleHyperRectangle */ public DoubleHyperRectangle(String label, DoubleRangePair... pairs) { - super(label, convertToLongRangePairArray(pairs)); + super(label, convertToLongRangePairs(pairs)); } - private static LongRangePair[] convertToLongRangePairArray(DoubleRangePair... pairs) { + private static LongRangePair[] convertToLongRangePairs(DoubleRangePair... pairs) { if (pairs == null || pairs.length == 0) { throw new IllegalArgumentException("Pairs cannot be null or empty"); } @@ -62,12 +62,12 @@ public DoubleRangePair(double minIn, boolean minInclusive, double maxIn, boolean } if (!maxInclusive) { - // Why no Math.nextDown? - maxIn = Math.nextAfter(maxIn, Double.NEGATIVE_INFINITY); + maxIn = Math.nextDown(maxIn); } if (minIn > maxIn) { - throw new IllegalArgumentException("Minimum cannot be greater than maximum"); + throw new IllegalArgumentException( + "Minimum cannot be greater than maximum, max=" + maxIn + ", min=" + minIn); } this.min = minIn; diff --git a/lucene/facet/src/java/org/apache/lucene/facet/hyperrectangle/HyperRectangle.java b/lucene/facet/src/java/org/apache/lucene/facet/hyperrectangle/HyperRectangle.java index 5280df0584be..3bfe6f3edfc5 100644 --- a/lucene/facet/src/java/org/apache/lucene/facet/hyperrectangle/HyperRectangle.java +++ b/lucene/facet/src/java/org/apache/lucene/facet/hyperrectangle/HyperRectangle.java @@ -85,7 +85,8 @@ public LongRangePair(long minIn, boolean minInclusive, long maxIn, boolean maxIn } if (minIn > maxIn) { - throw new IllegalArgumentException("Minimum cannot be greater than maximum"); + throw new IllegalArgumentException( + "Minimum cannot be greater than maximum, max=" + maxIn + ", min=" + minIn); } this.min = minIn; diff --git a/lucene/facet/src/java/org/apache/lucene/facet/hyperrectangle/HyperRectangleFacetCounts.java b/lucene/facet/src/java/org/apache/lucene/facet/hyperrectangle/HyperRectangleFacetCounts.java index 40380b29cfb0..123322db5e62 100644 --- a/lucene/facet/src/java/org/apache/lucene/facet/hyperrectangle/HyperRectangleFacetCounts.java +++ b/lucene/facet/src/java/org/apache/lucene/facet/hyperrectangle/HyperRectangleFacetCounts.java @@ -47,38 +47,17 @@ public class HyperRectangleFacetCounts extends Facets { protected int totCount; /** - * Create HyperRectangleFacetCounts using + * Create HyperRectangleFacetCounts using this * * @param field Field name * @param hits Hits to facet on - * @param hyperRectangles List of long hyper rectangle facets + * @param hyperRectangles List of hyper rectangle facets * @throws IOException If there is a problem reading the field */ public HyperRectangleFacetCounts( - String field, FacetsCollector hits, LongHyperRectangle... hyperRectangles) - throws IOException { - this(true, field, hits, hyperRectangles); - } - - /** - * Create HyperRectangleFacetCounts using - * - * @param field Field name - * @param hits Hits to facet on - * @param hyperRectangles List of double hyper rectangle facets - * @throws IOException If there is a problem reading the field - */ - public HyperRectangleFacetCounts( - String field, FacetsCollector hits, DoubleHyperRectangle... hyperRectangles) - throws IOException { - this(true, field, hits, hyperRectangles); - } - - private HyperRectangleFacetCounts( - boolean discarded, String field, FacetsCollector hits, HyperRectangle... hyperRectangles) - throws IOException { + String field, FacetsCollector hits, HyperRectangle... hyperRectangles) throws IOException { assert hyperRectangles.length > 0 : "Hyper rectangle ranges cannot be empty"; - assert isHyperRectangleDimsConsistent(hyperRectangles) + assert areHyperRectangleDimsConsistent(hyperRectangles) : "All hyper rectangles must be the same dimensionality"; this.field = field; this.hyperRectangles = hyperRectangles; @@ -87,7 +66,7 @@ assert isHyperRectangleDimsConsistent(hyperRectangles) count(field, hits.getMatchingDocs()); } - private boolean isHyperRectangleDimsConsistent(HyperRectangle[] hyperRectangles) { + private boolean areHyperRectangleDimsConsistent(HyperRectangle[] hyperRectangles) { int dims = hyperRectangles[0].dims; return Arrays.stream(hyperRectangles).allMatch(hyperRectangle -> hyperRectangle.dims == dims); } @@ -107,7 +86,7 @@ private void count(String field, List matchingDocs continue; } - for (int doc = it.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; ) { + for (int doc = it.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = it.nextDoc()) { if (binaryDocValues.advanceExact(doc)) { long[] point = LongPoint.unpack(binaryDocValues.binaryValue()); assert point.length == dims @@ -136,7 +115,6 @@ private void count(String field, List matchingDocs totCount++; } } - doc = it.nextDoc(); } } } @@ -148,7 +126,7 @@ public FacetResult getTopChildren(int topN, String dim, String... path) throws I throw new IllegalArgumentException( "invalid dim \"" + dim + "\"; should be \"" + field + "\""); } - if (path.length != 0) { + if (path != null && path.length != 0) { throw new IllegalArgumentException("path.length should be 0"); } LabelAndValue[] labelValues = new LabelAndValue[counts.length];