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/12 15:32:24 UTC
svn commit: r1695510 - in
/lucene/dev/branches/lucene6699/lucene/spatial3d/src:
java/org/apache/lucene/bkdtree3d/ java/org/apache/lucene/geo3d/ resources/
resources/META-INF/ resources/META-INF/services/
test/org/apache/lucene/bkdtree3d/
Author: mikemccand
Date: Wed Aug 12 13:32:24 2015
New Revision: 1695510
URL: http://svn.apache.org/r1695510
Log:
LUCENE-6699: add basic test for the point field / query
Added:
lucene/dev/branches/lucene6699/lucene/spatial3d/src/resources/
lucene/dev/branches/lucene6699/lucene/spatial3d/src/resources/META-INF/
lucene/dev/branches/lucene6699/lucene/spatial3d/src/resources/META-INF/services/
lucene/dev/branches/lucene6699/lucene/spatial3d/src/resources/META-INF/services/org.apache.lucene.codecs.DocValuesFormat
lucene/dev/branches/lucene6699/lucene/spatial3d/src/test/org/apache/lucene/bkdtree3d/TestGeo3DPointField.java
- copied, changed from r1695494, lucene/dev/branches/lucene6699/lucene/spatial3d/src/test/org/apache/lucene/bkdtree3d/TestBKD3DTree.java
Removed:
lucene/dev/branches/lucene6699/lucene/spatial3d/src/test/org/apache/lucene/bkdtree3d/TestBKD3DTree.java
Modified:
lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/BKD3DTreeWriter.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/geo3d/GeoPoint.java
Modified: lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/BKD3DTreeWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/BKD3DTreeWriter.java?rev=1695510&r1=1695509&r2=1695510&view=diff
==============================================================================
--- lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/BKD3DTreeWriter.java (original)
+++ lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/BKD3DTreeWriter.java Wed Aug 12 13:32:24 2015
@@ -641,9 +641,9 @@ class BKD3DTreeWriter {
if (nodeID >= leafNodeOffset) {
// Leaf node: write block
if (DEBUG) System.out.println(" leaf");
- assert maxX > minX;
- assert maxY > minY;
- assert maxZ > minZ;
+ assert maxX >= minX;
+ assert maxY >= minY;
+ assert maxZ >= minZ;
//System.out.println("\nleaf:\n lat range: " + ((long) maxLatEnc-minLatEnc));
//System.out.println(" lon range: " + ((long) maxLonEnc-minLonEnc));
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=1695510&r1=1695509&r2=1695510&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 Wed Aug 12 13:32:24 2015
@@ -46,6 +46,7 @@ public final class Geo3DPointField exten
*/
public Geo3DPointField(String name, final PlanetModel planetModel, final double lat, final double lon) {
super(name, TYPE);
+ System.out.println("HERE: " + lat);
final GeoPoint point = new GeoPoint(planetModel, lat, lon);
byte[] bytes = new byte[12];
BKD3DTreeDocValuesFormat.writeInt(BKD3DTreeDocValuesFormat.encodeValue(point.x), bytes, 0);
Modified: lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/geo3d/GeoPoint.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/geo3d/GeoPoint.java?rev=1695510&r1=1695509&r2=1695510&view=diff
==============================================================================
--- lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/geo3d/GeoPoint.java (original)
+++ lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/geo3d/GeoPoint.java Wed Aug 12 13:32:24 2015
@@ -85,10 +85,12 @@ public class GeoPoint extends Vector {
public GeoPoint(final double magnitude, final double x, final double y, final double z, double lat, double lon) {
super(x * magnitude, y * magnitude, z * magnitude);
this.magnitude = magnitude;
- if (lat > Math.PI * 0.5 || lat < -Math.PI * 0.5)
- throw new IllegalArgumentException("Latitude out of range");
- if (lon < -Math.PI || lon > Math.PI)
- throw new IllegalArgumentException("Longitude out of range");
+ if (lat > Math.PI * 0.5 || lat < -Math.PI * 0.5) {
+ throw new IllegalArgumentException("Latitude " + lat + " is out of range: must range from -Math.PI/2 to Math.PI/2");
+ }
+ if (lon < -Math.PI || lon > Math.PI) {
+ throw new IllegalArgumentException("Longitude " + lon + " is out of range: must range from -Math.PI to Math.PI");
+ }
this.latitude = lat;
this.longitude = lon;
}
Added: lucene/dev/branches/lucene6699/lucene/spatial3d/src/resources/META-INF/services/org.apache.lucene.codecs.DocValuesFormat
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6699/lucene/spatial3d/src/resources/META-INF/services/org.apache.lucene.codecs.DocValuesFormat?rev=1695510&view=auto
==============================================================================
--- lucene/dev/branches/lucene6699/lucene/spatial3d/src/resources/META-INF/services/org.apache.lucene.codecs.DocValuesFormat (added)
+++ lucene/dev/branches/lucene6699/lucene/spatial3d/src/resources/META-INF/services/org.apache.lucene.codecs.DocValuesFormat Wed Aug 12 13:32:24 2015
@@ -0,0 +1,17 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+org.apache.lucene.bkdtree3d.BKD3DTreeDocValuesFormat
+
Copied: lucene/dev/branches/lucene6699/lucene/spatial3d/src/test/org/apache/lucene/bkdtree3d/TestGeo3DPointField.java (from r1695494, lucene/dev/branches/lucene6699/lucene/spatial3d/src/test/org/apache/lucene/bkdtree3d/TestBKD3DTree.java)
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6699/lucene/spatial3d/src/test/org/apache/lucene/bkdtree3d/TestGeo3DPointField.java?p2=lucene/dev/branches/lucene6699/lucene/spatial3d/src/test/org/apache/lucene/bkdtree3d/TestGeo3DPointField.java&p1=lucene/dev/branches/lucene6699/lucene/spatial3d/src/test/org/apache/lucene/bkdtree3d/TestBKD3DTree.java&r1=1695494&r2=1695510&rev=1695510&view=diff
==============================================================================
--- lucene/dev/branches/lucene6699/lucene/spatial3d/src/test/org/apache/lucene/bkdtree3d/TestBKD3DTree.java (original)
+++ lucene/dev/branches/lucene6699/lucene/spatial3d/src/test/org/apache/lucene/bkdtree3d/TestGeo3DPointField.java Wed Aug 12 13:32:24 2015
@@ -17,8 +17,16 @@ package org.apache.lucene.bkdtree3d;
* limitations under the License.
*/
+import org.apache.lucene.document.Document;
+import org.apache.lucene.geo3d.GeoCircle;
+import org.apache.lucene.geo3d.PlanetModel;
+import org.apache.lucene.index.DirectoryReader;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.search.DocIdSet;
import org.apache.lucene.search.DocIdSetIterator;
+import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.IndexInput;
@@ -32,10 +40,35 @@ import java.util.List;
import static org.apache.lucene.bkdtree3d.BKD3DTreeDocValuesFormat.encodeValue;
-public class TestBKD3DTree extends LuceneTestCase {
+public class TestGeo3DPointField extends LuceneTestCase {
public void testBasic() 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 BKD3DTreeDocValuesFormat(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);
+ // We can't wrap with "exotic" readers because the query must see the BKD3DDVFormat:
+ IndexSearcher s = newSearcher(r, false);
+ assertEquals(1, s.search(new PointInGeo3DShapeQuery(PlanetModel.WGS84,
+ "field",
+ new GeoCircle(PlanetModel.WGS84, toRadians(50), toRadians(-97), Math.PI/180.)), 1).totalHits);
+ w.close();
+ r.close();
+ dir.close();
+ }
+
+ private static double toRadians(double degrees) {
+ return Math.PI*(degrees/360.0);
+ }
+
+ public void testBKDBasic() throws Exception {
+ Directory dir = newDirectory();
IndexOutput out = dir.createOutput("bkd", IOContext.DEFAULT);
BKD3DTreeWriter w = new BKD3DTreeWriter();
@@ -126,7 +159,7 @@ public class TestBKD3DTree extends Lucen
}
}
- public void testRandom() throws Exception {
+ public void testBKDRandom() throws Exception {
List<Point> points = new ArrayList<>();
int numPoints = atLeast(10000);
Directory dir = newDirectory();