Fix the special corner case, that an exclusive range starting/ending with MAX_VALUE/MIN_VALUE overflows the bounds. Return a empty TermEnum in this case (which causes an EMPTY_DOCIDSET returned from getDocIdSet) (see LUCENE-1461 discussions)

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@788728 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Uwe Schindler 2009-06-26 15:02:49 +00:00
parent 2e7267478d
commit d820e34a26
3 changed files with 28 additions and 4 deletions

View File

@ -290,7 +290,10 @@ public final class NumericRangeQuery extends MultiTermQuery {
} else if (min instanceof Double) {
minBound = NumericUtils.doubleToSortableLong(min.doubleValue());
}
if (!minInclusive && min != null) minBound++;
if (!minInclusive && min != null) {
if (minBound == Long.MAX_VALUE) break;
minBound++;
}
// upper
long maxBound = Long.MAX_VALUE;
@ -299,7 +302,10 @@ public final class NumericRangeQuery extends MultiTermQuery {
} else if (max instanceof Double) {
maxBound = NumericUtils.doubleToSortableLong(max.doubleValue());
}
if (!maxInclusive && max != null) maxBound--;
if (!maxInclusive && max != null) {
if (maxBound == Long.MIN_VALUE) break;
maxBound--;
}
NumericUtils.splitLongRange(new NumericUtils.LongRangeBuilder() {
//@Override
@ -319,7 +325,10 @@ public final class NumericRangeQuery extends MultiTermQuery {
} else if (min instanceof Float) {
minBound = NumericUtils.floatToSortableInt(min.floatValue());
}
if (!minInclusive && min != null) minBound++;
if (!minInclusive && min != null) {
if (minBound == Integer.MAX_VALUE) break;
minBound++;
}
// upper
int maxBound = Integer.MAX_VALUE;
@ -328,7 +337,10 @@ public final class NumericRangeQuery extends MultiTermQuery {
} else if (max instanceof Float) {
maxBound = NumericUtils.floatToSortableInt(max.floatValue());
}
if (!maxInclusive && max != null) maxBound--;
if (!maxInclusive && max != null) {
if (maxBound == Integer.MIN_VALUE) break;
maxBound--;
}
NumericUtils.splitIntRange(new NumericUtils.IntRangeBuilder() {
//@Override

View File

@ -150,6 +150,12 @@ public class TestNumericRangeQuery32 extends LuceneTestCase {
public void testInverseRange() throws Exception {
NumericRangeFilter f = NumericRangeFilter.newIntRange("field8", 8, new Integer(1000), new Integer(-1000), true, true);
assertSame("A inverse range should return the EMPTY_DOCIDSET instance", DocIdSet.EMPTY_DOCIDSET, f.getDocIdSet(searcher.getIndexReader()));
f = NumericRangeFilter.newIntRange("field8", 8, new Integer(Integer.MAX_VALUE), null, false, false);
assertSame("A exclusive range starting with Integer.MAX_VALUE should return the EMPTY_DOCIDSET instance",
DocIdSet.EMPTY_DOCIDSET, f.getDocIdSet(searcher.getIndexReader()));
f = NumericRangeFilter.newIntRange("field8", 8, null, new Integer(Integer.MIN_VALUE), false, false);
assertSame("A exclusive range ending with Integer.MIN_VALUE should return the EMPTY_DOCIDSET instance",
DocIdSet.EMPTY_DOCIDSET, f.getDocIdSet(searcher.getIndexReader()));
}
private void testLeftOpenRange(int precisionStep) throws Exception {

View File

@ -150,6 +150,12 @@ public class TestNumericRangeQuery64 extends LuceneTestCase {
public void testInverseRange() throws Exception {
NumericRangeFilter f = NumericRangeFilter.newLongRange("field8", 8, new Long(1000L), new Long(-1000L), true, true);
assertSame("A inverse range should return the EMPTY_DOCIDSET instance", DocIdSet.EMPTY_DOCIDSET, f.getDocIdSet(searcher.getIndexReader()));
f = NumericRangeFilter.newLongRange("field8", 8, new Long(Long.MAX_VALUE), null, false, false);
assertSame("A exclusive range starting with Long.MAX_VALUE should return the EMPTY_DOCIDSET instance",
DocIdSet.EMPTY_DOCIDSET, f.getDocIdSet(searcher.getIndexReader()));
f = NumericRangeFilter.newLongRange("field8", 8, null, new Long(Long.MIN_VALUE), false, false);
assertSame("A exclusive range ending with Long.MIN_VALUE should return the EMPTY_DOCIDSET instance",
DocIdSet.EMPTY_DOCIDSET, f.getDocIdSet(searcher.getIndexReader()));
}
private void testLeftOpenRange(int precisionStep) throws Exception {