mirror of https://github.com/apache/lucene.git
SOLR-11073: Fix overflow in interval faceting when querying Long limits
This commit is contained in:
parent
e23ac243ef
commit
3bd1115964
|
@ -354,6 +354,9 @@ Bug Fixes
|
|||
* SOLR-11043: Fix facet.range.method=dv and interval facets on single-valued float fields with negative values.
|
||||
(Tomás Fernández Löbbe, Steve Rowe)
|
||||
|
||||
* SOLR-11073: Fix overflow in interval faceting when querying Long limits (e.g. (Long.MAX_VALUE TO Long.MAX_VALUE])
|
||||
(Tomás Fernández Löbbe)
|
||||
|
||||
Optimizations
|
||||
----------------------
|
||||
|
||||
|
|
|
@ -505,6 +505,11 @@ public class IntervalFacets implements Iterable<FacetInterval> {
|
|||
*/
|
||||
private int count;
|
||||
|
||||
/**
|
||||
* If this field is set to true, this interval {@code #getCount()} will always return 0.
|
||||
*/
|
||||
private boolean includeNoDocs = false;
|
||||
|
||||
/**
|
||||
*
|
||||
* Constructor that accepts un-parsed interval faceting syntax. See {@link IntervalFacets} for details
|
||||
|
@ -646,9 +651,16 @@ public class IntervalFacets implements Iterable<FacetInterval> {
|
|||
throw new AssertionError();
|
||||
}
|
||||
if (startOpen) {
|
||||
if (startLimit == Long.MAX_VALUE) {
|
||||
/*
|
||||
* This interval can match no docs
|
||||
*/
|
||||
includeNoDocs = true;
|
||||
} else {
|
||||
startLimit++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (end == null) {
|
||||
|
@ -674,10 +686,17 @@ public class IntervalFacets implements Iterable<FacetInterval> {
|
|||
throw new AssertionError();
|
||||
}
|
||||
if (endOpen) {
|
||||
if (endLimit == Long.MIN_VALUE) {
|
||||
/*
|
||||
* This interval can match no docs
|
||||
*/
|
||||
includeNoDocs = true;
|
||||
} else {
|
||||
endLimit--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private BytesRef getLimitFromString(SchemaField schemaField, StringBuilder builder) throws SyntaxError {
|
||||
String value = builder.toString().trim();
|
||||
|
@ -882,6 +901,9 @@ public class IntervalFacets implements Iterable<FacetInterval> {
|
|||
* @return The count of document that matched this interval
|
||||
*/
|
||||
public int getCount() {
|
||||
if (includeNoDocs) {
|
||||
return 0;
|
||||
}
|
||||
return this.count;
|
||||
}
|
||||
|
||||
|
@ -906,7 +928,6 @@ public class IntervalFacets implements Iterable<FacetInterval> {
|
|||
*/
|
||||
@Override
|
||||
public Iterator<FacetInterval> iterator() {
|
||||
|
||||
return new ArrayList<FacetInterval>(Arrays.asList(intervals)).iterator();
|
||||
}
|
||||
|
||||
|
|
|
@ -664,11 +664,19 @@ public class TestIntervalFaceting extends SolrTestCaseJ4 {
|
|||
assertU(adoc("id", "12", "test_l_dv", String.valueOf(Long.MAX_VALUE - 3)));
|
||||
assertU(adoc("id", "13", "test_l_dv", String.valueOf(Long.MAX_VALUE - 2)));
|
||||
assertU(adoc("id", "14", "test_l_dv", String.valueOf(Long.MAX_VALUE - 1)));
|
||||
assertU(adoc("id", "15", "test_l_dv", String.valueOf(Long.MAX_VALUE)));
|
||||
assertU(adoc("id", "16", "test_l_dv", String.valueOf(Long.MIN_VALUE)));
|
||||
assertU(commit());
|
||||
|
||||
assertIntervalQuery("test_l_dv", "[0," + Integer.MAX_VALUE + "]", "10");
|
||||
assertIntervalQuery("test_l_dv", "[" + Integer.MAX_VALUE + "," + Long.MAX_VALUE + "]", "3");
|
||||
assertIntervalQuery("test_l_dv", "[" + Integer.MAX_VALUE + ",*]", "3");
|
||||
assertIntervalQuery("test_l_dv", "(10," + Long.MAX_VALUE + "]", "4");
|
||||
assertIntervalQuery("test_l_dv", "[" + Long.MAX_VALUE + "," + Long.MAX_VALUE + "]", "1");
|
||||
assertIntervalQuery("test_l_dv", "[" + Long.MAX_VALUE + ",*]", "1");
|
||||
assertIntervalQuery("test_l_dv", "(" + Long.MAX_VALUE + ",*]", "0");
|
||||
assertIntervalQuery("test_l_dv", "(*, " + Long.MIN_VALUE + "]", "1");
|
||||
assertIntervalQuery("test_l_dv", "(*, " + Long.MIN_VALUE + ")", "0");
|
||||
assertIntervalQuery("test_l_dv", "(" + (Long.MAX_VALUE - 1) + ",*]", "1");
|
||||
assertIntervalQuery("test_l_dv", "[" + (Long.MAX_VALUE - 1) + ",*]", "2");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -732,6 +740,9 @@ public class TestIntervalFaceting extends SolrTestCaseJ4 {
|
|||
assertIntervalQuery(field, "(0, " + Float.MAX_VALUE + "]", "2");
|
||||
assertIntervalQuery(field, "(0, " + Float.POSITIVE_INFINITY + ")", "2");
|
||||
assertIntervalQuery(field, "(0, " + Float.POSITIVE_INFINITY + "]", "3");
|
||||
assertIntervalQuery(field, "[-0.0, 0.0]", "2");
|
||||
assertIntervalQuery(field, "[-0.0, 0.0)", "1");
|
||||
assertIntervalQuery(field, "(-0.0, 0.0]", "1");
|
||||
|
||||
if (testDouble) {
|
||||
clearIndex();
|
||||
|
|
Loading…
Reference in New Issue