You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ds...@apache.org on 2014/12/05 16:27:12 UTC

svn commit: r1643331 - in /lucene/dev/branches/branch_5x: ./ lucene/ lucene/spatial/ lucene/spatial/src/java/org/apache/lucene/spatial/prefix/tree/ lucene/spatial/src/test/org/apache/lucene/spatial/prefix/ lucene/spatial/src/test/org/apache/lucene/spat...

Author: dsmiley
Date: Fri Dec  5 15:27:11 2014
New Revision: 1643331

URL: http://svn.apache.org/r1643331
Log:
LUCENE-6092: NumberRangePrefixTree toRangeShape normalization bug

Modified:
    lucene/dev/branches/branch_5x/   (props changed)
    lucene/dev/branches/branch_5x/lucene/   (props changed)
    lucene/dev/branches/branch_5x/lucene/spatial/   (props changed)
    lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/tree/NumberRangePrefixTree.java
    lucene/dev/branches/branch_5x/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/DateNRStrategyTest.java
    lucene/dev/branches/branch_5x/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/tree/DateRangePrefixTreeTest.java

Modified: lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/tree/NumberRangePrefixTree.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/tree/NumberRangePrefixTree.java?rev=1643331&r1=1643330&r2=1643331&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/tree/NumberRangePrefixTree.java (original)
+++ lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/tree/NumberRangePrefixTree.java Fri Dec  5 15:27:11 2014
@@ -232,20 +232,34 @@ public abstract class NumberRangePrefixT
   public Shape toRangeShape(Shape start, Shape end) {
     if (!(start instanceof LevelledValue && end instanceof LevelledValue))
       throw new IllegalArgumentException("Must pass "+LevelledValue.class+" but got "+start.getClass());
-    LevelledValue minLV = (LevelledValue) start;
-    LevelledValue maxLV = (LevelledValue) end;
-    if (minLV.equals(maxLV))
-      return minLV;
-    //Optimize precision of the range, e.g. April 1st to April 30th is April.
-    minLV = minLV.getLVAtLevel(truncateStartVals(minLV, 0));
-    maxLV = maxLV.getLVAtLevel(truncateEndVals(maxLV, 0));
-    int cmp = comparePrefixLV(minLV, maxLV);
+    LevelledValue startLV = (LevelledValue) start;
+    LevelledValue endLV = (LevelledValue) end;
+    //note: this normalization/optimization process is actually REQUIRED based on assumptions elsewhere.
+    //Normalize start & end
+    startLV = startLV.getLVAtLevel(truncateStartVals(startLV, 0)); // chops off trailing min-vals (zeroes)
+    endLV = endLV.getLVAtLevel(truncateEndVals(endLV, 0)); // chops off trailing max-vals
+    //Optimize to just start or end if it's equivalent, e.g. April to April 1st is April 1st.
+    int cmp = comparePrefixLV(startLV, endLV);
     if (cmp > 0) {
       throw new IllegalArgumentException("Wrong order: "+start+" TO "+end);
     }
-    if (cmp == 0 && minLV.getLevel() == maxLV.getLevel())
-      return minLV;
-    return new NRShape(minLV, maxLV);
+    if (cmp == 0) {//one is a prefix of the other
+      if (startLV.getLevel() == endLV.getLevel()) {
+        //same
+        return startLV;
+      } else if (endLV.getLevel() > startLV.getLevel()) {
+        // e.g. April to April 1st
+        if (truncateStartVals(endLV, startLV.getLevel()) == startLV.getLevel()) {
+          return endLV;
+  }
+      } else {//minLV level > maxLV level
+        // e.g. April 30 to April
+        if (truncateEndVals(startLV, endLV.getLevel()) == endLV.getLevel()) {
+          return startLV;
+        }
+      }
+    }
+    return new NRShape(startLV, endLV);
   }
 
   /** From lv.getLevel on up, it returns the first Level seen with val != 0. It doesn't check past endLevel. */

Modified: lucene/dev/branches/branch_5x/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/DateNRStrategyTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/DateNRStrategyTest.java?rev=1643331&r1=1643330&r2=1643331&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/DateNRStrategyTest.java (original)
+++ lucene/dev/branches/branch_5x/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/DateNRStrategyTest.java Fri Dec  5 15:27:11 2014
@@ -27,6 +27,7 @@ import org.junit.Ignore;
 import org.junit.Test;
 
 import java.io.IOException;
+import java.text.ParseException;
 import java.util.Calendar;
 
 public class DateNRStrategyTest extends RandomSpatialOpStrategyTestCase {
@@ -65,12 +66,6 @@ public class DateNRStrategyTest extends
     testOperationRandomShapes(SpatialOperation.Contains);
   }
 
-  @Test @Ignore("see LUCENE-5692")
-  @Repeat(iterations = ITERATIONS)
-  public void testDisjoint() throws IOException {
-    testOperationRandomShapes(SpatialOperation.IsDisjointTo);
-  }
-
   @Test
   public void testWithinSame() throws IOException {
     final Calendar cal = tree.newCal();

Modified: lucene/dev/branches/branch_5x/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/tree/DateRangePrefixTreeTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/tree/DateRangePrefixTreeTest.java?rev=1643331&r1=1643330&r2=1643331&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/tree/DateRangePrefixTreeTest.java (original)
+++ lucene/dev/branches/branch_5x/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/tree/DateRangePrefixTreeTest.java Fri Dec  5 15:27:11 2014
@@ -157,7 +157,9 @@ public class DateRangePrefixTreeTest ext
 
     assertEquals("2014", tree.parseShape("[2014-01-01 TO 2014-12-31]").toString());
 
-    assertEquals("2014", tree.parseShape("[2014-01 TO 2014]").toString());
+    assertEquals("2014",    tree.parseShape("[2014-01 TO 2014]").toString());
+    assertEquals("2014-01", tree.parseShape("[2014 TO 2014-01]").toString());
+    assertEquals("2014-12", tree.parseShape("[2014-12 TO 2014]").toString());
 
     assertEquals("[2014 TO 2014-04-06]", tree.parseShape("[2014-01 TO 2014-04-06]").toString());