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/06/10 20:41:23 UTC

svn commit: r1601734 - in /lucene/dev/trunk/lucene/spatial/src: java/org/apache/lucene/spatial/prefix/tree/NumberRangePrefixTree.java test/org/apache/lucene/spatial/prefix/tree/DateRangePrefixTreeTest.java

Author: dsmiley
Date: Tue Jun 10 18:41:22 2014
New Revision: 1601734

URL: http://svn.apache.org/r1601734
Log:
LUCENE-5648: Bug fix for detecting Contains relation when on the edge.

Modified:
    lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/tree/NumberRangePrefixTree.java
    lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/tree/DateRangePrefixTreeTest.java

Modified: lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/tree/NumberRangePrefixTree.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/tree/NumberRangePrefixTree.java?rev=1601734&r1=1601733&r2=1601734&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/tree/NumberRangePrefixTree.java (original)
+++ lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/tree/NumberRangePrefixTree.java Tue Jun 10 18:41:22 2014
@@ -730,13 +730,24 @@ public abstract class NumberRangePrefixT
       if (endCmp < 0) {//end comes before this cell
         return SpatialRelation.DISJOINT;
       }
-      if ((startCmp < 0 || startCmp == 0 && nrShape.getMinLV().getLevel() <= getLevel())
-          && (endCmp > 0 || endCmp == 0 && nrShape.getMaxLV().getLevel() <= getLevel()))
+      int nrMinLevel = nrShape.getMinLV().getLevel();
+      int nrMaxLevel = nrShape.getMaxLV().getLevel();
+      if ((startCmp < 0 || startCmp == 0 && nrMinLevel <= getLevel())
+          && (endCmp > 0 || endCmp == 0 && nrMaxLevel <= getLevel()))
         return SpatialRelation.WITHIN;//or equals
-      if (startCmp == 0 && endCmp == 0
-          && nrShape.getMinLV().getLevel() >= getLevel() && nrShape.getMaxLV().getLevel() >= getLevel())
-        return SpatialRelation.CONTAINS;
-      return SpatialRelation.INTERSECTS;
+      //At this point it's Contains or Within.
+      if (startCmp != 0 || endCmp != 0)
+        return SpatialRelation.INTERSECTS;
+      //if min or max Level is less, it might be on the equivalent edge.
+      for (;nrMinLevel < getLevel(); nrMinLevel++) {
+        if (getValAtLevel(nrMinLevel + 1) != 0)
+          return SpatialRelation.INTERSECTS;
+      }
+      for (;nrMaxLevel < getLevel(); nrMaxLevel++) {
+        if (getValAtLevel(nrMaxLevel + 1) != getNumSubCells(getLVAtLevel(nrMaxLevel-1)) - 1)
+          return SpatialRelation.INTERSECTS;
+      }
+      return SpatialRelation.CONTAINS;
     }
 
     @Override
@@ -806,6 +817,24 @@ public abstract class NumberRangePrefixT
         str += "•";//bullet (won't be confused with textual representation)
       return str;
     }
+
+    /** Configure your IDE to use this. */
+    public String toStringDebug() {
+      String pretty = toString();
+      if (getLevel() == 0)
+        return pretty;
+      //now prefix it by an array of integers of the cell levels
+      StringBuilder buf = new StringBuilder(100);
+      buf.append('[');
+      for (int level = 1; level <= getLevel(); level++) {
+        if (level != 1)
+          buf.append(',');
+        buf.append(getLVAtLevel(level).cellNumber);
+      }
+      buf.append("] ").append(pretty);
+      return buf.toString();
+    }
+
   } // END OF NRCell
 
 }

Modified: lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/tree/DateRangePrefixTreeTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/tree/DateRangePrefixTreeTest.java?rev=1601734&r1=1601733&r2=1601734&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/tree/DateRangePrefixTreeTest.java (original)
+++ lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/tree/DateRangePrefixTreeTest.java Tue Jun 10 18:41:22 2014
@@ -135,6 +135,10 @@ public class DateRangePrefixTreeTest ext
   }
 
   public void testShapeRelations() throws ParseException {
+    //note: left range is 264000 at the thousand year level whereas right value is exact year
+    assertEquals(SpatialRelation.WITHIN,
+        tree.parseShape("[-264000 TO -264000-11-20]").relate(tree.parseShape("-264000")));
+
     Shape shapeA = tree.parseShape("[3122-01-23 TO 3122-11-27]");
     Shape shapeB = tree.parseShape("[3122-08 TO 3122-11]");
     assertEquals(SpatialRelation.INTERSECTS, shapeA.relate(shapeB));