You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2015/08/19 00:49:07 UTC

svn commit: r1696511 - in /lucene/dev/branches/lucene6699/lucene: sandbox/src/java/org/apache/lucene/bkdtree/ spatial3d/src/java/org/apache/lucene/bkdtree3d/ spatial3d/src/java/org/apache/lucene/geo3d/ spatial3d/src/test/org/apache/lucene/bkdtree3d/

Author: mikemccand
Date: Tue Aug 18 22:49:06 2015
New Revision: 1696511

URL: http://svn.apache.org/r1696511
Log:
LUCENE-6699: rename relations

Modified:
    lucene/dev/branches/lucene6699/lucene/sandbox/src/java/org/apache/lucene/bkdtree/BKDPointInPolygonQuery.java
    lucene/dev/branches/lucene6699/lucene/sandbox/src/java/org/apache/lucene/bkdtree/BKDTreeReader.java
    lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/BKD3DTreeReader.java
    lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/PointInGeo3DShapeQuery.java
    lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/geo3d/XYZSolid.java
    lucene/dev/branches/lucene6699/lucene/spatial3d/src/test/org/apache/lucene/bkdtree3d/TestGeo3DPointField.java

Modified: lucene/dev/branches/lucene6699/lucene/sandbox/src/java/org/apache/lucene/bkdtree/BKDPointInPolygonQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6699/lucene/sandbox/src/java/org/apache/lucene/bkdtree/BKDPointInPolygonQuery.java?rev=1696511&r1=1696510&r2=1696511&view=diff
==============================================================================
--- lucene/dev/branches/lucene6699/lucene/sandbox/src/java/org/apache/lucene/bkdtree/BKDPointInPolygonQuery.java (original)
+++ lucene/dev/branches/lucene6699/lucene/sandbox/src/java/org/apache/lucene/bkdtree/BKDPointInPolygonQuery.java Tue Aug 18 22:49:06 2015
@@ -158,8 +158,6 @@ public class BKDPointInPolygonQuery exte
         BKDTreeSortedNumericDocValues treeDV = (BKDTreeSortedNumericDocValues) sdv;
         BKDTreeReader tree = treeDV.getBKDTreeReader();
         
-        // TODO: make this more efficient: as we recurse the BKD tree we should check whether the
-        // bbox we are recursing into intersects our shape; Apache SIS may have (non-GPL!) code to do this?
         DocIdSet result = tree.intersect(minLat, maxLat, minLon, maxLon,
                                          new BKDTreeReader.LatLonFilter() {
                                            @Override
@@ -172,13 +170,13 @@ public class BKDPointInPolygonQuery exte
                                              if (GeoUtils.rectWithinPoly(cellLonMin, cellLatMin, cellLonMax, cellLatMax,
                                                                          polyLons, polyLats,
                                                                          minLon, minLat, maxLon, maxLat)) {
-                                               return BKDTreeReader.Relation.INSIDE;
+                                               return BKDTreeReader.Relation.CELL_INSIDE_SHAPE;
                                              } else if (GeoUtils.rectCrossesPoly(cellLonMin, cellLatMin, cellLonMax, cellLatMax,
                                                                                  polyLons, polyLats,
                                                                                  minLon, minLat, maxLon, maxLat)) {
-                                               return BKDTreeReader.Relation.CROSSES;
+                                               return BKDTreeReader.Relation.SHAPE_CROSSES_CELL;
                                              } else {
-                                               return BKDTreeReader.Relation.OUTSIDE;
+                                               return BKDTreeReader.Relation.SHAPE_OUTSIDE_CELL;
                                              }
                                            }
                                          }, treeDV.delegate);

Modified: lucene/dev/branches/lucene6699/lucene/sandbox/src/java/org/apache/lucene/bkdtree/BKDTreeReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6699/lucene/sandbox/src/java/org/apache/lucene/bkdtree/BKDTreeReader.java?rev=1696511&r1=1696510&r2=1696511&view=diff
==============================================================================
--- lucene/dev/branches/lucene6699/lucene/sandbox/src/java/org/apache/lucene/bkdtree/BKDTreeReader.java (original)
+++ lucene/dev/branches/lucene6699/lucene/sandbox/src/java/org/apache/lucene/bkdtree/BKDTreeReader.java Tue Aug 18 22:49:06 2015
@@ -38,7 +38,7 @@ final class BKDTreeReader implements Acc
   final int maxDoc;
   final IndexInput in;
 
-  enum Relation {INSIDE, CROSSES, OUTSIDE};
+  enum Relation {CELL_INSIDE_SHAPE, SHAPE_CROSSES_CELL, SHAPE_OUTSIDE_CELL};
 
   interface LatLonFilter {
     // TODO: move DVs/encoding out on top: this method should just take a docID
@@ -190,19 +190,21 @@ final class BKDTreeReader implements Acc
 
     // 2.06 sec -> 1.52 sec for 225 OSM London queries:
     if (state.latLonFilter != null) {
-      if (cellLatMinEnc >= state.latMinEnc ||
-          cellLatMaxEnc <= state.latMaxEnc ||
-          cellLonMinEnc >= state.lonMinEnc ||
-          cellLonMaxEnc <= state.lonMaxEnc) {
+
+      // Only call the filter when the current cell does not fully contain the bbox:
+      if (cellLatMinEnc > state.latMinEnc || cellLatMaxEnc < state.latMaxEnc ||
+          cellLonMinEnc > state.lonMinEnc || cellLonMaxEnc < state.lonMaxEnc) {
+
+        // nocommit explain why this fails, e.g. ot TestBKDTree.testRandomTiny -seed 80479DBEF3DE1A76 -verbose
         Relation r = state.latLonFilter.compare(BKDTreeWriter.decodeLat(cellLatMinEnc),
                                                 BKDTreeWriter.decodeLat(cellLatMaxEnc),
                                                 BKDTreeWriter.decodeLon(cellLonMinEnc),
                                                 BKDTreeWriter.decodeLon(cellLonMaxEnc));
-        //System.out.println("BKD.intersect cellLat=" + BKDTreeWriter.decodeLat(cellLatMinEnc) + " TO " + BKDTreeWriter.decodeLat(cellLatMaxEnc) + ", cellLon=" + BKDTreeWriter.decodeLon(cellLonMinEnc) + " TO " + BKDTreeWriter.decodeLon(cellLonMaxEnc) + " compare=" + r);
-        if (r == Relation.OUTSIDE) {
+        // System.out.println("BKD.intersect cellLat=" + BKDTreeWriter.decodeLat(cellLatMinEnc) + " TO " + BKDTreeWriter.decodeLat(cellLatMaxEnc) + ", cellLon=" + BKDTreeWriter.decodeLon(cellLonMinEnc) + " TO " + BKDTreeWriter.decodeLon(cellLonMaxEnc) + " compare=" + r);
+        if (r == Relation.SHAPE_OUTSIDE_CELL) {
           // This cell is fully outside of the query shape: stop recursing
           return 0;
-        } else if (r == Relation.INSIDE) {
+        } else if (r == Relation.CELL_INSIDE_SHAPE) {
           // This cell is fully inside of the query shape: recursively add all points in this cell without filtering
           return addAll(state, nodeID);
         } else {
@@ -211,7 +213,7 @@ final class BKDTreeReader implements Acc
       }
     // TODO: clean this up: the bbox case should also just be a filter, and we should assert filter != null at the start
     } else if (state.latMinEnc <= cellLatMinEnc && state.latMaxEnc >= cellLatMaxEnc && state.lonMinEnc <= cellLonMinEnc && state.lonMaxEnc >= cellLonMaxEnc) {
-      // Optimize the case when the query fully contains this cell: we can
+      // Bbox query: optimize the case when the query fully contains this cell: we can
       // recursively add all points without checking if they match the query:
       return addAll(state, nodeID);
     }

Modified: lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/BKD3DTreeReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/BKD3DTreeReader.java?rev=1696511&r1=1696510&r2=1696511&view=diff
==============================================================================
--- lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/BKD3DTreeReader.java (original)
+++ lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/BKD3DTreeReader.java Tue Aug 18 22:49:06 2015
@@ -38,7 +38,7 @@ final class BKD3DTreeReader implements A
   final int maxDoc;
   final IndexInput in;
 
-  enum Relation {INSIDE, CROSSES, OUTSIDE};
+  enum Relation {CELL_INSIDE_SHAPE, SHAPE_CROSSES_CELL, SHAPE_OUTSIDE_CELL, SHAPE_INSIDE_CELL};
 
   interface ValueFilter {
     boolean accept(int docID);
@@ -173,20 +173,23 @@ final class BKD3DTreeReader implements A
         cellZMin <= state.zMin ||
         cellZMax <= state.zMax) {
 
+      // Only call the filter when the current cell does not fully contain the bbox:
       Relation r = state.valueFilter.compare(cellXMin, cellXMax,
                                              cellYMin, cellYMax,
                                              cellZMin, cellZMax);
       //System.out.println("  relation: " + r);
 
-      if (r == Relation.OUTSIDE) {
+      if (r == Relation.SHAPE_OUTSIDE_CELL) {
         // This cell is fully outside of the query shape: stop recursing
         return 0;
-      } else if (r == Relation.INSIDE) {
+      } else if (r == Relation.CELL_INSIDE_SHAPE) {
         // This cell is fully inside of the query shape: recursively add all points in this cell without filtering
         return addAll(state, nodeID);
       } else {
         // The cell crosses the shape boundary, so we fall through and do full filtering
       }
+    } else {
+      assert state.valueFilter.compare(cellXMin, cellXMax, cellYMin, cellYMax, cellZMin, cellZMax) == Relation.SHAPE_INSIDE_CELL: "got " + state.valueFilter.compare(cellXMin, cellXMax, cellYMin, cellYMax, cellZMin, cellZMax);
     }
 
     //System.out.println("\nintersect node=" + nodeID + " vs " + leafNodeOffset);

Modified: lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/PointInGeo3DShapeQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/PointInGeo3DShapeQuery.java?rev=1696511&r1=1696510&r2=1696511&view=diff
==============================================================================
--- lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/PointInGeo3DShapeQuery.java (original)
+++ lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/PointInGeo3DShapeQuery.java Tue Aug 18 22:49:06 2015
@@ -17,6 +17,7 @@ package org.apache.lucene.bkdtree3d;
  * limitations under the License.
  */
 
+import org.apache.lucene.geo3d.Vector;
 import org.apache.lucene.geo3d.GeoArea;
 import org.apache.lucene.geo3d.GeoAreaFactory;
 import org.apache.lucene.geo3d.GeoShape;
@@ -103,9 +104,6 @@ public class PointInGeo3DShapeQuery exte
 
         assert xyzSolid.getRelationship(shape) == GeoArea.WITHIN || xyzSolid.getRelationship(shape) == GeoArea.OVERLAPS;
         
-        // TODO: make this more efficient: as we recurse the BKD tree we should check whether the
-        // bbox we are recursing into intersects our shape; Apache SIS may have (non-GPL!) code to do this?
-        //DocIdSet result = tree.intersect(
         DocIdSet result = tree.intersect(Geo3DDocValuesFormat.encodeValue(bounds.getMinimumX()),
                                          Geo3DDocValuesFormat.encodeValue(bounds.getMaximumX()),
                                          Geo3DDocValuesFormat.encodeValue(bounds.getMinimumY()),
@@ -153,22 +151,22 @@ public class PointInGeo3DShapeQuery exte
                                              case GeoArea.CONTAINS:
                                                // Shape fully contains the cell
                                                //System.out.println("    inside");
-                                               return BKD3DTreeReader.Relation.INSIDE;
+                                               return BKD3DTreeReader.Relation.CELL_INSIDE_SHAPE;
                                              case GeoArea.OVERLAPS:
                                                // They do overlap but neither contains the other:
                                                //System.out.println("    crosses1");
-                                               return BKD3DTreeReader.Relation.CROSSES;
+                                               return BKD3DTreeReader.Relation.SHAPE_CROSSES_CELL;
                                              case GeoArea.WITHIN:
                                                // Cell fully contains the shape:
                                                //System.out.println("    crosses2");
-                                               return BKD3DTreeReader.Relation.CROSSES;
+                                               return BKD3DTreeReader.Relation.SHAPE_INSIDE_CELL;
                                              case GeoArea.DISJOINT:
                                                // They do not overlap at all
                                                //System.out.println("    outside");
-                                               return BKD3DTreeReader.Relation.OUTSIDE;
+                                               return BKD3DTreeReader.Relation.SHAPE_OUTSIDE_CELL;
                                              default:
                                                assert false;
-                                               return BKD3DTreeReader.Relation.CROSSES;
+                                               return BKD3DTreeReader.Relation.SHAPE_CROSSES_CELL;
                                              }
                                            }
                                          });

Modified: lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/geo3d/XYZSolid.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/geo3d/XYZSolid.java?rev=1696511&r1=1696510&r2=1696511&view=diff
==============================================================================
--- lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/geo3d/XYZSolid.java (original)
+++ lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/geo3d/XYZSolid.java Tue Aug 18 22:49:06 2015
@@ -266,13 +266,14 @@ public class XYZSolid extends BaseXYZSol
     //System.err.println(this+" getrelationship with "+path);
     final int insideRectangle = isShapeInsideArea(path);
     if (insideRectangle == SOME_INSIDE) {
-      //System.err.println(" some inside");
+      //System.err.println(" some shape points inside area");
       return OVERLAPS;
     }
 
     // Figure out if the entire XYZArea is contained by the shape.
     final int insideShape = isAreaInsideShape(path);
     if (insideShape == SOME_INSIDE) {
+      //System.err.println(" some area points inside shape");
       return OVERLAPS;
     }
 
@@ -292,12 +293,12 @@ public class XYZSolid extends BaseXYZSol
     }
 
     if (insideRectangle == ALL_INSIDE) {
-      //System.err.println(" shape inside rectangle");
+      //System.err.println(" all shape points inside area");
       return WITHIN;
     }
 
     if (insideShape == ALL_INSIDE) {
-      //System.err.println(" shape contains rectangle");
+      //System.err.println(" all area points inside shape");
       return CONTAINS;
     }
     //System.err.println(" disjoint");

Modified: lucene/dev/branches/lucene6699/lucene/spatial3d/src/test/org/apache/lucene/bkdtree3d/TestGeo3DPointField.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6699/lucene/spatial3d/src/test/org/apache/lucene/bkdtree3d/TestGeo3DPointField.java?rev=1696511&r1=1696510&r2=1696511&view=diff
==============================================================================
--- lucene/dev/branches/lucene6699/lucene/spatial3d/src/test/org/apache/lucene/bkdtree3d/TestGeo3DPointField.java (original)
+++ lucene/dev/branches/lucene6699/lucene/spatial3d/src/test/org/apache/lucene/bkdtree3d/TestGeo3DPointField.java Tue Aug 18 22:49:06 2015
@@ -131,7 +131,7 @@ public class TestGeo3DPointField extends
                                   public BKD3DTreeReader.Relation compare(int xMin, int xMax,
                                                           int yMin, int yMax,
                                                           int zMin, int zMax) {
-                                    return BKD3DTreeReader.Relation.INSIDE;
+                                    return BKD3DTreeReader.Relation.SHAPE_INSIDE_CELL;
                                   }
 
                                 });
@@ -279,22 +279,22 @@ public class TestGeo3DPointField extends
                                                                             int cellYMin, int cellYMax,
                                                                             int cellZMin, int cellZMax) {
                                       if (cellXMin > xMaxEnc || cellXMax < xMinEnc) {
-                                        return BKD3DTreeReader.Relation.OUTSIDE;
+                                        return BKD3DTreeReader.Relation.SHAPE_OUTSIDE_CELL;
                                       }
                                       if (cellYMin > yMaxEnc || cellYMax < yMinEnc) {
-                                        return BKD3DTreeReader.Relation.OUTSIDE;
+                                        return BKD3DTreeReader.Relation.SHAPE_OUTSIDE_CELL;
                                       }
                                       if (cellZMin > zMaxEnc || cellZMax < zMinEnc) {
-                                        return BKD3DTreeReader.Relation.OUTSIDE;
+                                        return BKD3DTreeReader.Relation.SHAPE_OUTSIDE_CELL;
                                       }
 
                                       if (cellXMin >= xMinEnc && cellXMax <= xMaxEnc &&
                                           cellYMin >= yMinEnc && cellYMax <= yMaxEnc &&
                                           cellZMin >= zMinEnc && cellZMax <= zMaxEnc) {
-                                        return BKD3DTreeReader.Relation.INSIDE;
+                                        return BKD3DTreeReader.Relation.CELL_INSIDE_SHAPE;
                                       }
 
-                                      return BKD3DTreeReader.Relation.CROSSES;
+                                      return BKD3DTreeReader.Relation.SHAPE_CROSSES_CELL;
                                     }
                                   });
 
@@ -612,9 +612,9 @@ public class TestGeo3DPointField extends
                                                  decodeValue(encodeValue(point1.y)),
                                                  decodeValue(encodeValue(point1.z)));
 
-                  boolean expected = deleted.contains(id) == false && shape.isWithin(point2);
+                  boolean expected = ((deleted.contains(id) == false) && shape.isWithin(point2));
                   if (hits.get(docID) != expected) {
-                    fail(Thread.currentThread().getName() + ": iter=" + iter + " id=" + id + " docID=" + docID + " lat=" + lats[id] + " lon=" + lons[id] + " expected " + expected + " but got: " + hits.get(docID) + " deleted?=" + deleted.contains(id) + "\n  point1=" + point1 + "\n  point2=" + point2 + "\n  query=" + query);
+                    fail(Thread.currentThread().getName() + ": iter=" + iter + " id=" + id + " docID=" + docID + " lat=" + lats[id] + " lon=" + lons[id] + " expected " + expected + " but got: " + hits.get(docID) + " deleted?=" + deleted.contains(id) + "\n  point1=" + point1 + ", iswithin="+shape.isWithin(point1)+"\n  point2=" + point2 + ", iswithin="+shape.isWithin(point2) + "\n  query=" + query);
                   }
                 } else {
                   assertFalse(hits.get(docID));