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/27 20:04:03 UTC

svn commit: r1698202 - in /lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d: Geo3DDocValuesFormat.java PointInGeo3DShapeQuery.java

Author: mikemccand
Date: Thu Aug 27 18:04:02 2015
New Revision: 1698202

URL: http://svn.apache.org/r1698202
Log:
LUCENE-6699: clip the min/max in the global bbox to fall within the planet model; add nocommit

Modified:
    lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/Geo3DDocValuesFormat.java
    lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/PointInGeo3DShapeQuery.java

Modified: lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/Geo3DDocValuesFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/Geo3DDocValuesFormat.java?rev=1698202&r1=1698201&r2=1698202&view=diff
==============================================================================
--- lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/Geo3DDocValuesFormat.java (original)
+++ lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/Geo3DDocValuesFormat.java Thu Aug 27 18:04:02 2015
@@ -22,6 +22,7 @@ import org.apache.lucene.codecs.DocValue
 import org.apache.lucene.codecs.DocValuesProducer;
 import org.apache.lucene.codecs.lucene50.Lucene50DocValuesFormat;
 import org.apache.lucene.geo3d.PlanetModel;
+import org.apache.lucene.geo3d.Vector;
 import org.apache.lucene.index.SegmentReadState;
 import org.apache.lucene.index.SegmentWriteState;
 
@@ -84,6 +85,9 @@ public class Geo3DDocValuesFormat extend
     this(BKD3DTreeWriter.DEFAULT_MAX_POINTS_IN_LEAF_NODE, BKD3DTreeWriter.DEFAULT_MAX_POINTS_SORT_IN_HEAP);
   }
 
+  // nocommit require PlanetModel here, at write time?  then we could use the true max to encode, and write that into the doc values, and
+  // confirm it's == to the search-time planet model
+
   /** Creates this with custom configuration.
    *
    * @param maxPointsInLeafNode Maximum number of points in each leaf cell.  Smaller values create a deeper tree with larger in-heap index and possibly
@@ -118,6 +122,16 @@ public class Geo3DDocValuesFormat extend
   private static final double ENCODE_SCALE = Integer.MAX_VALUE / MAX_ABS_VALUE;
   private static final double DECODE_SCALE = MAX_ABS_VALUE / Integer.MAX_VALUE;
 
+  /** Clips the incoming value to the allowed min/max range before encoding, instead of throwing an exception. */
+  static int encodeValueLenient(double x) {
+    if (x > MAX_ABS_VALUE) {
+      x = MAX_ABS_VALUE;
+    } else if (x < -MAX_ABS_VALUE) {
+      x = -MAX_ABS_VALUE;
+    }
+    return encodeValue(x);
+  }
+    
   static int encodeValue(double x) {
     if (x < -MAX_ABS_VALUE) {
       throw new IllegalArgumentException("value=" + x + " is out-of-bounds (less than MIN_VALUE=" + (-MAX_ABS_VALUE) + ")");

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=1698202&r1=1698201&r2=1698202&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 Thu Aug 27 18:04:02 2015
@@ -94,6 +94,7 @@ public class PointInGeo3DShapeQuery exte
         XYZBounds bounds = new XYZBounds();
         shape.getBounds(bounds);
 
+        /*
         GeoArea xyzSolid = GeoAreaFactory.makeGeoArea(planetModel,
                                                       bounds.getMinimumX(),
                                                       bounds.getMaximumX(),
@@ -103,7 +104,7 @@ public class PointInGeo3DShapeQuery exte
                                                       bounds.getMaximumZ());
 
         assert xyzSolid.getRelationship(shape) == GeoArea.WITHIN || xyzSolid.getRelationship(shape) == GeoArea.OVERLAPS: "expected WITHIN (1) or OVERLAPS (2) but got " + xyzSolid.getRelationship(shape) + "; shape="+shape+"; XYZSolid="+xyzSolid;
-
+        */
 
         // The fudge factor here (+/- 2.0 * MINIMUM_RESOLUTION) is here to ensure that
         // you get a WITHIN rather than an OVERLAPS if you expand the bounding box by
@@ -111,12 +112,12 @@ public class PointInGeo3DShapeQuery exte
         // the box. Otherwise according to the (revised) definition of getRelationship(),
         // you could technically get either one.
 
-        DocIdSet result = tree.intersect(Geo3DDocValuesFormat.encodeValue(bounds.getMinimumX() - 2.0 * Vector.MINIMUM_RESOLUTION),
-                                         Geo3DDocValuesFormat.encodeValue(bounds.getMaximumX() + 2.0 * Vector.MINIMUM_RESOLUTION),
-                                         Geo3DDocValuesFormat.encodeValue(bounds.getMinimumY() - 2.0 * Vector.MINIMUM_RESOLUTION),
-                                         Geo3DDocValuesFormat.encodeValue(bounds.getMaximumY() + 2.0 * Vector.MINIMUM_RESOLUTION),
-                                         Geo3DDocValuesFormat.encodeValue(bounds.getMinimumZ() - 2.0 * Vector.MINIMUM_RESOLUTION),
-                                         Geo3DDocValuesFormat.encodeValue(bounds.getMaximumZ() + 2.0 * Vector.MINIMUM_RESOLUTION),
+        DocIdSet result = tree.intersect(Geo3DDocValuesFormat.encodeValueLenient(bounds.getMinimumX() - 2.0 * Vector.MINIMUM_RESOLUTION),
+                                         Geo3DDocValuesFormat.encodeValueLenient(bounds.getMaximumX() + 2.0 * Vector.MINIMUM_RESOLUTION),
+                                         Geo3DDocValuesFormat.encodeValueLenient(bounds.getMinimumY() - 2.0 * Vector.MINIMUM_RESOLUTION),
+                                         Geo3DDocValuesFormat.encodeValueLenient(bounds.getMaximumY() + 2.0 * Vector.MINIMUM_RESOLUTION),
+                                         Geo3DDocValuesFormat.encodeValueLenient(bounds.getMinimumZ() - 2.0 * Vector.MINIMUM_RESOLUTION),
+                                         Geo3DDocValuesFormat.encodeValueLenient(bounds.getMaximumZ() + 2.0 * Vector.MINIMUM_RESOLUTION),
                                          new BKD3DTreeReader.ValueFilter() {
                                            @Override
                                            public boolean accept(int docID) {