lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r1698232 - in /lucene/dev/branches/lucene6699/lucene/spatial3d/src: java/org/apache/lucene/bkdtree3d/ test/org/apache/lucene/bkdtree3d/
Date Thu, 27 Aug 2015 21:56:15 GMT
Author: mikemccand
Date: Thu Aug 27 21:56:15 2015
New Revision: 1698232

URL: http://svn.apache.org/r1698232
Log:
LUCENE-6699: store planet's max in the index, and validate at search time

Modified:
    lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/Geo3DBinaryDocValues.java
    lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/Geo3DDocValuesConsumer.java
    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/Geo3DDocValuesProducer.java
    lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/Geo3DPointField.java
    lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/PointInGeo3DShapeQuery.java
    lucene/dev/branches/lucene6699/lucene/spatial3d/src/test/org/apache/lucene/bkdtree3d/TestGeo3DPointField.java

Modified: lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/Geo3DBinaryDocValues.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/Geo3DBinaryDocValues.java?rev=1698232&r1=1698231&r2=1698232&view=diff
==============================================================================
--- lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/Geo3DBinaryDocValues.java
(original)
+++ lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/Geo3DBinaryDocValues.java
Thu Aug 27 21:56:15 2015
@@ -23,10 +23,12 @@ import org.apache.lucene.util.BytesRef;
 class Geo3DBinaryDocValues extends BinaryDocValues {
   final BKD3DTreeReader bkdTreeReader;
   final BinaryDocValues delegate;
+  final double planetMax;
 
-  public Geo3DBinaryDocValues(BKD3DTreeReader bkdTreeReader, BinaryDocValues delegate) {
+  public Geo3DBinaryDocValues(BKD3DTreeReader bkdTreeReader, BinaryDocValues delegate, double
planetMax) {
     this.bkdTreeReader = bkdTreeReader;
     this.delegate = delegate;
+    this.planetMax = planetMax;
   }
 
   public BKD3DTreeReader getBKD3DTreeReader() {

Modified: lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/Geo3DDocValuesConsumer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/Geo3DDocValuesConsumer.java?rev=1698232&r1=1698231&r2=1698232&view=diff
==============================================================================
--- lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/Geo3DDocValuesConsumer.java
(original)
+++ lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/Geo3DDocValuesConsumer.java
Thu Aug 27 21:56:15 2015
@@ -17,14 +17,9 @@ package org.apache.lucene.bkdtree3d;
  * limitations under the License.
  */
 
-import java.io.Closeable;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
 import org.apache.lucene.codecs.CodecUtil;
 import org.apache.lucene.codecs.DocValuesConsumer;
+import org.apache.lucene.geo3d.PlanetModel;
 import org.apache.lucene.index.FieldInfo;
 import org.apache.lucene.index.IndexFileNames;
 import org.apache.lucene.index.SegmentWriteState;
@@ -32,6 +27,12 @@ import org.apache.lucene.store.IndexOutp
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.IOUtils;
 
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
 class Geo3DDocValuesConsumer extends DocValuesConsumer implements Closeable {
   final DocValuesConsumer delegate;
   final int maxPointsInLeafNode;
@@ -40,7 +41,7 @@ class Geo3DDocValuesConsumer extends Doc
   final Map<Integer,Long> fieldIndexFPs = new HashMap<>();
   final SegmentWriteState state;
 
-  public Geo3DDocValuesConsumer(DocValuesConsumer delegate, SegmentWriteState state, int
maxPointsInLeafNode, int maxPointsSortInHeap) throws IOException {
+  public Geo3DDocValuesConsumer(PlanetModel planetModel, DocValuesConsumer delegate, SegmentWriteState
state, int maxPointsInLeafNode, int maxPointsSortInHeap) throws IOException {
     BKD3DTreeWriter.verifyParams(maxPointsInLeafNode, maxPointsSortInHeap);
     this.delegate = delegate;
     this.maxPointsInLeafNode = maxPointsInLeafNode;
@@ -50,6 +51,10 @@ class Geo3DDocValuesConsumer extends Doc
     out = state.directory.createOutput(datFileName, state.context);
     CodecUtil.writeIndexHeader(out, Geo3DDocValuesFormat.DATA_CODEC_NAME, Geo3DDocValuesFormat.DATA_VERSION_CURRENT,
                                state.segmentInfo.getId(), state.segmentSuffix);
+
+    // We write the max for this PlanetModel into the index so we know we are decoding correctly
at search time, and so we can also do
+    // best-effort check that the search time PlanetModel "matches":
+    out.writeLong(Double.doubleToLongBits(planetModel.getMaximumMagnitude()));
   }
 
   @Override

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=1698232&r1=1698231&r2=1698232&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 21:56:15 2015
@@ -80,32 +80,33 @@ public class Geo3DDocValuesFormat extend
   
   private final DocValuesFormat delegate = new Lucene50DocValuesFormat();
 
+  private final PlanetModel planetModel;
+
   /** Default constructor */
   public Geo3DDocValuesFormat() {
-    this(BKD3DTreeWriter.DEFAULT_MAX_POINTS_IN_LEAF_NODE, BKD3DTreeWriter.DEFAULT_MAX_POINTS_SORT_IN_HEAP);
+    this(PlanetModel.WGS84, 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 planetModel the {@link PlanetModel} to use; this is only used when writing
    * @param maxPointsInLeafNode Maximum number of points in each leaf cell.  Smaller values
create a deeper tree with larger in-heap index and possibly
    *    faster searching.  The default is 1024.
    * @param maxPointsSortInHeap Maximum number of points where in-heap sort can be used.
 When the number of points exceeds this, a (slower)
    *    offline sort is used.  The default is 128 * 1024.
    *
    * @lucene.experimental */
-  public Geo3DDocValuesFormat(int maxPointsInLeafNode, int maxPointsSortInHeap) {
+  public Geo3DDocValuesFormat(PlanetModel planetModel, int maxPointsInLeafNode, int maxPointsSortInHeap)
{
     super("BKD3DTree");
     BKD3DTreeWriter.verifyParams(maxPointsInLeafNode, maxPointsSortInHeap);
     this.maxPointsInLeafNode = maxPointsInLeafNode;
     this.maxPointsSortInHeap = maxPointsSortInHeap;
+    this.planetModel = planetModel;
   }
 
   @Override
   public DocValuesConsumer fieldsConsumer(final SegmentWriteState state) throws IOException
{
-    return new Geo3DDocValuesConsumer(delegate.fieldsConsumer(state), state, maxPointsInLeafNode,
maxPointsSortInHeap);
+    return new Geo3DDocValuesConsumer(planetModel, delegate.fieldsConsumer(state), state,
maxPointsInLeafNode, maxPointsSortInHeap);
   }
 
   @Override
@@ -113,41 +114,34 @@ public class Geo3DDocValuesFormat extend
     return new Geo3DDocValuesProducer(delegate.fieldsProducer(state), state);
   }
 
-  // NOTE: this is from the max current PlanetModel (WGS84).  If a new
-  // PlanetModel shows up in the future with a bigger max, we have to revisit this, but users
will
-  // hit an exc from encodeValue:
-
-  static final double MAX_ABS_VALUE = 1.0011188180710464;
-
-  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;
+  static int encodeValueLenient(PlanetModel planetModel, double x) {
+    double max = planetModel.getMaximumMagnitude();
+    if (x > max) {
+      x = max;
+    } else if (x < -max) {
+      x = -max;
     }
-    return encodeValue(x);
+    return encodeValue(planetModel, 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) + ")");
+  static int encodeValue(PlanetModel planetModel, double x) {
+    double max = planetModel.getMaximumMagnitude();
+    if (x > max) {
+      throw new IllegalArgumentException("value=" + x + " is out-of-bounds (greater than
max for PlanetModel=" + planetModel + " " + max);
     }
-    if (x > MAX_ABS_VALUE) {
-      throw new IllegalArgumentException("value=" + x + " is out-of-bounds (greater than
MAX_VALUE=" + MAX_ABS_VALUE + ")");
+    if (x < -max) {
+      throw new IllegalArgumentException("value=" + x + " is out-of-bounds (less than than
-max for PlanetModel=" + planetModel + " " + max);
     }
-    long y = (long) (x * ENCODE_SCALE);
+    long y = (long) (x * (Integer.MAX_VALUE / max));
     assert y >= Integer.MIN_VALUE;
     assert y <= Integer.MAX_VALUE;
 
     return (int) y;
   }
 
-  static double decodeValue(int x) {
-    return x * DECODE_SCALE;
+  static double decodeValue(double planetMax, int x) {
+    return x * (planetMax / Integer.MAX_VALUE);
   }
 
   static int readInt(byte[] bytes, int offset) {

Modified: lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/Geo3DDocValuesProducer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/Geo3DDocValuesProducer.java?rev=1698232&r1=1698231&r2=1698232&view=diff
==============================================================================
--- lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/Geo3DDocValuesProducer.java
(original)
+++ lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/Geo3DDocValuesProducer.java
Thu Aug 27 21:56:15 2015
@@ -53,6 +53,7 @@ class Geo3DDocValuesProducer extends Doc
   private final int maxDoc;
   private final DocValuesProducer delegate;
   private final boolean merging;
+  private final double planetMax;
 
   public Geo3DDocValuesProducer(DocValuesProducer delegate, SegmentReadState state) throws
IOException {
     String metaFileName = IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix,
Geo3DDocValuesFormat.META_EXTENSION);
@@ -72,6 +73,7 @@ class Geo3DDocValuesProducer extends Doc
     datIn = state.directory.openInput(datFileName, state.context);
     CodecUtil.checkIndexHeader(datIn, Geo3DDocValuesFormat.DATA_CODEC_NAME, Geo3DDocValuesFormat.DATA_VERSION_START,
Geo3DDocValuesFormat.DATA_VERSION_CURRENT,
                                state.segmentInfo.getId(), state.segmentSuffix);
+    planetMax = Double.longBitsToDouble(datIn.readLong());
     ramBytesUsed = new AtomicLong(RamUsageEstimator.shallowSizeOfInstance(getClass()));
     maxDoc = state.segmentInfo.maxDoc();
     this.delegate = delegate;
@@ -88,6 +90,7 @@ class Geo3DDocValuesProducer extends Doc
     treeReaders.putAll(orig.treeReaders);
     merging = true;
     maxDoc = orig.maxDoc;
+    planetMax = orig.planetMax;
   }
 
   @Override
@@ -133,7 +136,7 @@ class Geo3DDocValuesProducer extends Doc
       }
     }
 
-    return new Geo3DBinaryDocValues(treeReader, delegate.getBinary(field));
+    return new Geo3DBinaryDocValues(treeReader, delegate.getBinary(field), planetMax);
   }
 
   @Override

Modified: lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/Geo3DPointField.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/Geo3DPointField.java?rev=1698232&r1=1698231&r2=1698232&view=diff
==============================================================================
--- lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/Geo3DPointField.java
(original)
+++ lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/Geo3DPointField.java
Thu Aug 27 21:56:15 2015
@@ -42,14 +42,11 @@ public final class Geo3DPointField exten
    *
    * @throws IllegalArgumentException if the field name is null or lat or lon are out of
bounds
    */
-  public Geo3DPointField(String name, final PlanetModel planetModel, final double lat, final
double lon) {
+  public Geo3DPointField(String name, PlanetModel planetModel, double lat, double lon) {
     super(name, TYPE);
+    // Translate lat/lon to x,y,z:
     final GeoPoint point = new GeoPoint(planetModel, lat, lon);
-    byte[] bytes = new byte[12];
-    Geo3DDocValuesFormat.writeInt(Geo3DDocValuesFormat.encodeValue(point.x), bytes, 0);
-    Geo3DDocValuesFormat.writeInt(Geo3DDocValuesFormat.encodeValue(point.y), bytes, 4);
-    Geo3DDocValuesFormat.writeInt(Geo3DDocValuesFormat.encodeValue(point.z), bytes, 8);
-    fieldsData = new BytesRef(bytes);
+    fillFieldsData(planetModel, point.x, point.y, point.z);
   }
 
   /** 
@@ -57,12 +54,16 @@ public final class Geo3DPointField exten
    *
    * @throws IllegalArgumentException if the field name is null or lat or lon are out of
bounds
    */
-  public Geo3DPointField(String name, double x, double y, double z) {
+  public Geo3DPointField(String name, PlanetModel planetModel, double x, double y, double
z) {
     super(name, TYPE);
+    fillFieldsData(planetModel, x, y, z);
+  }
+
+  private void fillFieldsData(PlanetModel planetModel, double x, double y, double z) {
     byte[] bytes = new byte[12];
-    Geo3DDocValuesFormat.writeInt(Geo3DDocValuesFormat.encodeValue(x), bytes, 0);
-    Geo3DDocValuesFormat.writeInt(Geo3DDocValuesFormat.encodeValue(y), bytes, 4);
-    Geo3DDocValuesFormat.writeInt(Geo3DDocValuesFormat.encodeValue(z), bytes, 8);
+    Geo3DDocValuesFormat.writeInt(Geo3DDocValuesFormat.encodeValue(planetModel, x), bytes,
0);
+    Geo3DDocValuesFormat.writeInt(Geo3DDocValuesFormat.encodeValue(planetModel, y), bytes,
4);
+    Geo3DDocValuesFormat.writeInt(Geo3DDocValuesFormat.encodeValue(planetModel, z), bytes,
8);
     fieldsData = new BytesRef(bytes);
   }
 }

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=1698232&r1=1698231&r2=1698232&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 21:56:15 2015
@@ -88,12 +88,16 @@ public class PointInGeo3DShapeQuery exte
         if (bdv instanceof Geo3DBinaryDocValues == false) {
           throw new IllegalStateException("field \"" + field + "\" was not indexed with Geo3DBinaryDocValuesFormat:
got: " + bdv);
         }
-        Geo3DBinaryDocValues treeDV = (Geo3DBinaryDocValues) bdv;
+        final Geo3DBinaryDocValues treeDV = (Geo3DBinaryDocValues) bdv;
         BKD3DTreeReader tree = treeDV.getBKD3DTreeReader();
 
         XYZBounds bounds = new XYZBounds();
         shape.getBounds(bounds);
 
+        if (planetModel.getMaximumMagnitude() != treeDV.planetMax) {
+          throw new IllegalStateException(planetModel + " is not the same one used during
indexing: max=" + planetModel.getMaximumMagnitude() + " vs indexing max=" + treeDV.planetMax);
+        }
+
         /*
         GeoArea xyzSolid = GeoAreaFactory.makeGeoArea(planetModel,
                                                       bounds.getMinimumX(),
@@ -112,12 +116,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.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),
+        DocIdSet result = tree.intersect(Geo3DDocValuesFormat.encodeValueLenient(planetModel,
bounds.getMinimumX() - 2.0 * Vector.MINIMUM_RESOLUTION),
+                                         Geo3DDocValuesFormat.encodeValueLenient(planetModel,
bounds.getMaximumX() + 2.0 * Vector.MINIMUM_RESOLUTION),
+                                         Geo3DDocValuesFormat.encodeValueLenient(planetModel,
bounds.getMinimumY() - 2.0 * Vector.MINIMUM_RESOLUTION),
+                                         Geo3DDocValuesFormat.encodeValueLenient(planetModel,
bounds.getMaximumY() + 2.0 * Vector.MINIMUM_RESOLUTION),
+                                         Geo3DDocValuesFormat.encodeValueLenient(planetModel,
bounds.getMinimumZ() - 2.0 * Vector.MINIMUM_RESOLUTION),
+                                         Geo3DDocValuesFormat.encodeValueLenient(planetModel,
bounds.getMaximumZ() + 2.0 * Vector.MINIMUM_RESOLUTION),
                                          new BKD3DTreeReader.ValueFilter() {
                                            @Override
                                            public boolean accept(int docID) {
@@ -129,9 +133,9 @@ public class PointInGeo3DShapeQuery exte
                                              }
 
                                              assert bytes.length == 12;
-                                             double x = Geo3DDocValuesFormat.decodeValue(Geo3DDocValuesFormat.readInt(bytes.bytes,
bytes.offset));
-                                             double y = Geo3DDocValuesFormat.decodeValue(Geo3DDocValuesFormat.readInt(bytes.bytes,
bytes.offset+4));
-                                             double z = Geo3DDocValuesFormat.decodeValue(Geo3DDocValuesFormat.readInt(bytes.bytes,
bytes.offset+8));
+                                             double x = Geo3DDocValuesFormat.decodeValue(treeDV.planetMax,
Geo3DDocValuesFormat.readInt(bytes.bytes, bytes.offset));
+                                             double y = Geo3DDocValuesFormat.decodeValue(treeDV.planetMax,
Geo3DDocValuesFormat.readInt(bytes.bytes, bytes.offset+4));
+                                             double z = Geo3DDocValuesFormat.decodeValue(treeDV.planetMax,
Geo3DDocValuesFormat.readInt(bytes.bytes, bytes.offset+8));
                                              // System.out.println("  accept docID=" + docID
+ " point: x=" + x + " y=" + y + " z=" + z);
 
                                              // True if x,y,z is within shape
@@ -176,12 +180,12 @@ public class PointInGeo3DShapeQuery exte
                                              cellYMinEnc = roundDown(cellYMinEnc);
                                              cellZMinEnc = roundDown(cellZMinEnc);
 
-                                             double cellXMin = Geo3DDocValuesFormat.decodeValue(cellXMinEnc);
-                                             double cellXMax = Geo3DDocValuesFormat.decodeValue(cellXMaxEnc);
-                                             double cellYMin = Geo3DDocValuesFormat.decodeValue(cellYMinEnc);
-                                             double cellYMax = Geo3DDocValuesFormat.decodeValue(cellYMaxEnc);
-                                             double cellZMin = Geo3DDocValuesFormat.decodeValue(cellZMinEnc);
-                                             double cellZMax = Geo3DDocValuesFormat.decodeValue(cellZMaxEnc);
+                                             double cellXMin = Geo3DDocValuesFormat.decodeValue(treeDV.planetMax,
cellXMinEnc);
+                                             double cellXMax = Geo3DDocValuesFormat.decodeValue(treeDV.planetMax,
cellXMaxEnc);
+                                             double cellYMin = Geo3DDocValuesFormat.decodeValue(treeDV.planetMax,
cellYMinEnc);
+                                             double cellYMax = Geo3DDocValuesFormat.decodeValue(treeDV.planetMax,
cellYMaxEnc);
+                                             double cellZMin = Geo3DDocValuesFormat.decodeValue(treeDV.planetMax,
cellZMinEnc);
+                                             double cellZMax = Geo3DDocValuesFormat.decodeValue(treeDV.planetMax,
cellZMaxEnc);
                                              //System.out.println("  compare: x=" + cellXMin
+ "-" + cellXMax + " y=" + cellYMin + "-" + cellYMax + " z=" + cellZMin + "-" + cellZMax);
 
                                              GeoArea xyzSolid = GeoAreaFactory.makeGeoArea(planetModel,
cellXMin, cellXMax, cellYMin, cellYMax, cellZMin, cellZMax);

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=1698232&r1=1698231&r2=1698232&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
Thu Aug 27 21:56:15 2015
@@ -79,7 +79,7 @@ public class TestGeo3DPointField extends
     int maxPointsInLeaf = TestUtil.nextInt(random(), 16, 2048);
     int maxPointsSortInHeap = TestUtil.nextInt(random(), maxPointsInLeaf, 1024*1024);
     IndexWriterConfig iwc = newIndexWriterConfig();
-    iwc.setCodec(TestUtil.alwaysDocValuesFormat(new Geo3DDocValuesFormat(maxPointsInLeaf,
maxPointsSortInHeap)));
+    iwc.setCodec(TestUtil.alwaysDocValuesFormat(new Geo3DDocValuesFormat(PlanetModel.WGS84,
maxPointsInLeaf, maxPointsSortInHeap)));
     IndexWriter w = new IndexWriter(dir, iwc);
     Document doc = new Document();
     doc.add(new Geo3DPointField("field", PlanetModel.WGS84, toRadians(50.7345267), toRadians(-97.5303555)));
@@ -95,6 +95,31 @@ public class TestGeo3DPointField extends
     dir.close();
   }
 
+  public void testPlanetModelChanged() throws Exception {
+    Directory dir = newDirectory();
+    int maxPointsInLeaf = TestUtil.nextInt(random(), 16, 2048);
+    int maxPointsSortInHeap = TestUtil.nextInt(random(), maxPointsInLeaf, 1024*1024);
+    IndexWriterConfig iwc = newIndexWriterConfig();
+    iwc.setCodec(TestUtil.alwaysDocValuesFormat(new Geo3DDocValuesFormat(PlanetModel.WGS84,
maxPointsInLeaf, maxPointsSortInHeap)));
+    IndexWriter w = new IndexWriter(dir, iwc);
+    Document doc = new Document();
+    doc.add(new Geo3DPointField("field", PlanetModel.WGS84, toRadians(50.7345267), toRadians(-97.5303555)));
+    w.addDocument(doc);
+    IndexReader r = DirectoryReader.open(w, true);
+    IndexSearcher s = new IndexSearcher(r);
+    try {
+      s.search(new PointInGeo3DShapeQuery(PlanetModel.SPHERE,
+                                          "field",
+                                          new GeoCircle(PlanetModel.WGS84, toRadians(50),
toRadians(-97), Math.PI/180.)), 1);
+      fail("did not hit exc");      
+    } catch (IllegalStateException ise) {
+      // expected
+    }
+    w.close();
+    r.close();
+    dir.close();
+  }
+
   private static double toRadians(double degrees) {
     return Math.PI*(degrees/360.0);
   }
@@ -176,14 +201,13 @@ public class TestGeo3DPointField extends
     }
   }
 
-  private double randomCoord() {
-    return (random().nextDouble()*2.0022) - 1.0011;
-    //return (random().nextDouble()*.002) - .001;
+  private double randomCoord(PlanetModel planetModel) {
+    return planetModel.getMaximumMagnitude() * 2*(random().nextDouble()-0.5);
   }
 
-  private Range randomRange() {
-    double x = randomCoord();
-    double y = randomCoord();
+  private Range randomRange(PlanetModel planetModel) {
+    double x = randomCoord(planetModel);
+    double y = randomCoord(planetModel);
     if (x < y) {
       return new Range(x, y);
     } else {
@@ -200,6 +224,13 @@ public class TestGeo3DPointField extends
 
     int maxPointsSortInHeap = TestUtil.nextInt(random(), maxPointsInLeaf, 1024*1024);
 
+    PlanetModel planetModel;
+    if (random().nextBoolean()) {
+      planetModel = PlanetModel.WGS84;
+    } else {
+      planetModel = PlanetModel.SPHERE;
+    }
+
     BKD3DTreeWriter w = new BKD3DTreeWriter(maxPointsInLeaf, maxPointsSortInHeap);
     for(int docID=0;docID<numPoints;docID++) {
       Point point;
@@ -207,22 +238,22 @@ public class TestGeo3DPointField extends
         // Dup point
         point = points.get(random().nextInt(points.size()));
       } else {
-        point = new Point(randomCoord(),
-                          randomCoord(),
-                          randomCoord());
+        point = new Point(randomCoord(planetModel),
+                          randomCoord(planetModel),
+                          randomCoord(planetModel));
       }
 
       if (VERBOSE) {
         System.err.println("  docID=" + docID + " point=" + point);
-        System.err.println("    x=" + encodeValue(point.x) +
-                           " y=" + encodeValue(point.y) +
-                           " z=" + encodeValue(point.z));
+        System.err.println("    x=" + encodeValue(planetModel, point.x) +
+                           " y=" + encodeValue(planetModel, point.y) +
+                           " z=" + encodeValue(planetModel, point.z));
       }
 
       points.add(point);
-      w.add(encodeValue(point.x),
-            encodeValue(point.y),
-            encodeValue(point.z),
+      w.add(encodeValue(planetModel, point.x),
+            encodeValue(planetModel, point.y),
+            encodeValue(planetModel, point.z),
             docID);
     }
 
@@ -236,16 +267,16 @@ public class TestGeo3DPointField extends
     int numIters = atLeast(100);
     for(int iter=0;iter<numIters;iter++) {
       // bbox
-      Range x = randomRange();
-      Range y = randomRange();
-      Range z = randomRange();
-
-      int xMinEnc = encodeValue(x.min);
-      int xMaxEnc = encodeValue(x.max);
-      int yMinEnc = encodeValue(y.min);
-      int yMaxEnc = encodeValue(y.max);
-      int zMinEnc = encodeValue(z.min);
-      int zMaxEnc = encodeValue(z.max);
+      Range x = randomRange(planetModel);
+      Range y = randomRange(planetModel);
+      Range z = randomRange(planetModel);
+
+      int xMinEnc = encodeValue(planetModel, x.min);
+      int xMaxEnc = encodeValue(planetModel, x.max);
+      int yMinEnc = encodeValue(planetModel, y.min);
+      int yMaxEnc = encodeValue(planetModel, y.max);
+      int zMinEnc = encodeValue(planetModel, z.min);
+      int zMaxEnc = encodeValue(planetModel, z.max);
 
       if (VERBOSE) {
         System.err.println("\nTEST: iter=" + iter + " bbox: x=" + x + " (" + xMinEnc + "
TO " + xMaxEnc+ ")" + " y=" + y + " (" + yMinEnc + " TO " + yMaxEnc + ")"  + " z=" + z + "
(" + zMinEnc + " TO " + zMaxEnc + ")" );
@@ -263,9 +294,9 @@ public class TestGeo3DPointField extends
                                       //System.out.println("  accept docID=" + docID + "
point=" + point + " (x=" + encodeValue(point.x) + " y=" + encodeValue(point.y) + " z=" + encodeValue(point.z)
+ ")");
 
                                       // System.out.println("  accept docID=" + docID + "
point: x=" + point.x + " y=" + point.y + " z=" + point.z);
-                                      int xEnc = encodeValue(point.x);
-                                      int yEnc = encodeValue(point.y);
-                                      int zEnc = encodeValue(point.z);
+                                      int xEnc = encodeValue(planetModel, point.x);
+                                      int yEnc = encodeValue(planetModel, point.y);
+                                      int zEnc = encodeValue(planetModel, point.z);
 
                                       boolean accept = xEnc >= xMinEnc && xEnc
<= xMaxEnc &&
                                         yEnc >= yMinEnc && yEnc <= yMaxEnc
&&
@@ -323,9 +354,9 @@ public class TestGeo3DPointField extends
         boolean actual = matches.get(docID);
 
         // We must quantize exactly as BKD tree does else we'll get false failures
-        int xEnc = encodeValue(point.x);
-        int yEnc = encodeValue(point.y);
-        int zEnc = encodeValue(point.z);
+        int xEnc = encodeValue(planetModel, point.x);
+        int yEnc = encodeValue(planetModel, point.y);
+        int zEnc = encodeValue(planetModel, point.z);
 
         boolean expected = xEnc >= xMinEnc && xEnc <= xMaxEnc &&
           yEnc >= yMinEnc && yEnc <= yMaxEnc &&
@@ -458,7 +489,7 @@ public class TestGeo3DPointField extends
     if (mbd != -1 && mbd < lats.length/100) {
       iwc.setMaxBufferedDocs(lats.length/100);
     }
-    final DocValuesFormat dvFormat = new Geo3DDocValuesFormat(maxPointsInLeaf, maxPointsSortInHeap);
+    final DocValuesFormat dvFormat = new Geo3DDocValuesFormat(planetModel, maxPointsInLeaf,
maxPointsSortInHeap);
     Codec codec = new Lucene53Codec() {
         @Override
         public DocValuesFormat getDocValuesFormatForField(String field) {
@@ -621,9 +652,9 @@ public class TestGeo3DPointField extends
                   GeoPoint point1 = new GeoPoint(planetModel, lats[id], lons[id]);
 
                   // Quantized point (32 bits per dim):
-                  GeoPoint point2 = new GeoPoint(decodeValue(encodeValue(point1.x)),
-                                                 decodeValue(encodeValue(point1.y)),
-                                                 decodeValue(encodeValue(point1.z)));
+                  GeoPoint point2 = new GeoPoint(decodeValue(planetModel.getMaximumMagnitude(),
encodeValue(planetModel, point1.x)),
+                                                 decodeValue(planetModel.getMaximumMagnitude(),
encodeValue(planetModel, point1.y)),
+                                                 decodeValue(planetModel.getMaximumMagnitude(),
encodeValue(planetModel, point1.z)));
 
                   if (shape.isWithin(point1) != shape.isWithin(point2)) {
                     if (VERBOSE) {



Mime
View raw message