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 2013/01/22 22:24:04 UTC
svn commit: r1437182 - in /lucene/dev/trunk/lucene: CHANGES.txt
spatial/src/java/org/apache/lucene/spatial/query/SpatialArgs.java
spatial/src/test/org/apache/lucene/spatial/SpatialArgsTest.java
Author: dsmiley
Date: Tue Jan 22 21:24:04 2013
New Revision: 1437182
URL: http://svn.apache.org/viewvc?rev=1437182&view=rev
Log:
LUCENE-4550: fix SpatialArgs.calcDistanceFromErrPct
Added:
lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialArgsTest.java (with props)
Modified:
lucene/dev/trunk/lucene/CHANGES.txt
lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/query/SpatialArgs.java
Modified: lucene/dev/trunk/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/CHANGES.txt?rev=1437182&r1=1437181&r2=1437182&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/CHANGES.txt (original)
+++ lucene/dev/trunk/lucene/CHANGES.txt Tue Jan 22 21:24:04 2013
@@ -70,6 +70,11 @@ Bug Fixes
* LUCENE-4705: Pass on FilterStrategy in FilteredQuery if the filtered query is
rewritten. (Simon Willnauer)
+* LUCENE-4550: Shapes wider than 180 degrees would use too much accuracy for the
+ PrefixTree based SpatialStrategy. For a pathological case of nearly 360
+ degrees and barely any height, it would generate so many indexed terms
+ (> 500k) that it could even cause an OutOfMemoryError. Fixed. (David Smiley)
+
======================= Lucene 4.1.0 =======================
Changes in backwards compatibility policy
Modified: lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/query/SpatialArgs.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/query/SpatialArgs.java?rev=1437182&r1=1437181&r2=1437182&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/query/SpatialArgs.java (original)
+++ lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/query/SpatialArgs.java Tue Jan 22 21:24:04 2013
@@ -47,7 +47,7 @@ public class SpatialArgs {
/**
* Computes the distance given a shape and the {@code distErrPct}. The
* algorithm is the fraction of the distance from the center of the query
- * shape to its furthest bounding box corner.
+ * shape to its closest bounding box corner.
*
* @param shape Mandatory.
* @param distErrPct 0 to 0.5
@@ -62,11 +62,13 @@ public class SpatialArgs {
return 0;
}
Rectangle bbox = shape.getBoundingBox();
- //The diagonal distance should be the same computed from any opposite corner,
- // and this is the longest distance that might be occurring within the shape.
- double diagonalDist = ctx.getDistCalc().distance(
- ctx.makePoint(bbox.getMinX(), bbox.getMinY()), bbox.getMaxX(), bbox.getMaxY());
- return diagonalDist * 0.5 * distErrPct;
+ //Compute the distance from the center to a corner. Because the distance
+ // to a bottom corner vs a top corner can vary in a geospatial scenario,
+ // take the closest one (greater precision).
+ Point ctr = bbox.getCenter();
+ double y = (ctr.getY() >= 0 ? bbox.getMaxY() : bbox.getMinY());
+ double diagonalDist = ctx.getDistCalc().distance(ctr, bbox.getMaxX(), y);
+ return diagonalDist * distErrPct;
}
/**
Added: lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialArgsTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialArgsTest.java?rev=1437182&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialArgsTest.java (added)
+++ lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialArgsTest.java Tue Jan 22 21:24:04 2013
@@ -0,0 +1,51 @@
+package org.apache.lucene.spatial;
+
+/*
+ * 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.
+ */
+
+import com.spatial4j.core.context.SpatialContext;
+import com.spatial4j.core.shape.Shape;
+import org.apache.lucene.spatial.query.SpatialArgs;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class SpatialArgsTest {
+
+ @Test
+ public void calcDistanceFromErrPct() {
+ final SpatialContext ctx = SpatialContext.GEO;
+ final double DEP = 0.5;//distErrPct
+
+ //the result is the diagonal distance from the center to the closest corner,
+ // times distErrPct
+
+ Shape superwide = ctx.makeRectangle(-180, 180, 0, 0);
+ //0 distErrPct means 0 distance always
+ assertEquals(0, SpatialArgs.calcDistanceFromErrPct(superwide, 0, ctx), 0);
+ assertEquals(180 * DEP, SpatialArgs.calcDistanceFromErrPct(superwide, DEP, ctx), 0);
+
+ Shape supertall = ctx.makeRectangle(0, 0, -90, 90);
+ assertEquals(90 * DEP, SpatialArgs.calcDistanceFromErrPct(supertall, DEP, ctx), 0);
+
+ Shape upperhalf = ctx.makeRectangle(-180, 180, 0, 90);
+ assertEquals(45 * DEP, SpatialArgs.calcDistanceFromErrPct(upperhalf, DEP, ctx), 0.0001);
+
+ Shape midCircle = ctx.makeCircle(0, 0, 45);
+ assertEquals(60 * DEP, SpatialArgs.calcDistanceFromErrPct(midCircle, DEP, ctx), 0.0001);
+ }
+}