lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From uschind...@apache.org
Subject svn commit: r788728 - in /lucene/java/trunk/src: java/org/apache/lucene/search/NumericRangeQuery.java test/org/apache/lucene/search/TestNumericRangeQuery32.java test/org/apache/lucene/search/TestNumericRangeQuery64.java
Date Fri, 26 Jun 2009 15:02:49 GMT
Author: uschindler
Date: Fri Jun 26 15:02:49 2009
New Revision: 788728

URL: http://svn.apache.org/viewvc?rev=788728&view=rev
Log:
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)

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/search/NumericRangeQuery.java
    lucene/java/trunk/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java
    lucene/java/trunk/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/NumericRangeQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/NumericRangeQuery.java?rev=788728&r1=788727&r2=788728&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/NumericRangeQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/NumericRangeQuery.java Fri Jun 26
15:02:49 2009
@@ -290,7 +290,10 @@
           } 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 @@
           } 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 @@
           } 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 @@
           } 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

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java?rev=788728&r1=788727&r2=788728&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java Fri Jun
26 15:02:49 2009
@@ -150,6 +150,12 @@
   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 {

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java?rev=788728&r1=788727&r2=788728&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java Fri Jun
26 15:02:49 2009
@@ -150,6 +150,12 @@
   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 {



Mime
View raw message