Apache Lucene open-source search software
LUCENE-4375 Fix use of BBoxWithin BBoxIntersects and IsWithin
David Wayne Smiley15b4b09ff353
diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/RecursivePrefixTreeStrategy.java b/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/RecursivePrefixTreeStrategy.javaindex c3b9914d237..dcbb21525b4 100644--- a/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/RecursivePrefixTreeStrategy.java+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/RecursivePrefixTreeStrategy.java@@ -51,7 +51,7 @@ public class RecursivePrefixTreeStrategy extends PrefixTreeStrategy {@Overridepublic Filter makeFilter(SpatialArgs args) {final SpatialOperation op = args.getOperation();- if (! SpatialOperation.is(op, SpatialOperation.IsWithin, SpatialOperation.Intersects, SpatialOperation.BBoxWithin, SpatialOperation.BBoxIntersects))+ if (op != SpatialOperation.Intersects)throw new UnsupportedSpatialOperation(op);Shape shape = args.getShape();@@ -59,7 +59,7 @@ public class RecursivePrefixTreeStrategy extends PrefixTreeStrategy {int detailLevel = grid.getLevelForDistance(args.resolveDistErr(ctx, distErrPct));return new RecursivePrefixTreeFilter(- getFieldName(), grid,shape, prefixGridScanLevel, detailLevel);+ getFieldName(), grid, shape, prefixGridScanLevel, detailLevel);}}diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/TermQueryPrefixTreeStrategy.java b/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/TermQueryPrefixTreeStrategy.javaindex 38f1d4909f0..169dda449dd 100644--- a/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/TermQueryPrefixTreeStrategy.java+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/TermQueryPrefixTreeStrategy.java@@ -44,7 +44,7 @@ public class TermQueryPrefixTreeStrategy extends PrefixTreeStrategy {@Overridepublic Filter makeFilter(SpatialArgs args) {final SpatialOperation op = args.getOperation();- if (! SpatialOperation.is(op, SpatialOperation.IsWithin, SpatialOperation.Intersects, SpatialOperation.BBoxWithin, SpatialOperation.BBoxIntersects))+ if (op != SpatialOperation.Intersects)throw new UnsupportedSpatialOperation(op);Shape shape = args.getShape();diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/query/SpatialArgs.java b/lucene/spatial/src/java/org/apache/lucene/spatial/query/SpatialArgs.javaindex fc40a1bd95f..5b171fb86e6 100644--- a/lucene/spatial/src/java/org/apache/lucene/spatial/query/SpatialArgs.java+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/query/SpatialArgs.java@@ -109,10 +109,7 @@ public class SpatialArgs {this.operation = operation;}- /** Considers {@link SpatialOperation#BBoxWithin} in returning the shape. */public Shape getShape() {- if (shape != null && (operation == SpatialOperation.BBoxWithin || operation == SpatialOperation.BBoxIntersects))- return shape.getBoundingBox();return shape;}diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/query/SpatialOperation.java b/lucene/spatial/src/java/org/apache/lucene/spatial/query/SpatialOperation.javaindex 3aab090d515..e786974401f 100644--- a/lucene/spatial/src/java/org/apache/lucene/spatial/query/SpatialOperation.java+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/query/SpatialOperation.java@@ -38,7 +38,10 @@ public class SpatialOperation implements Serializable {private static final List<SpatialOperation> list = new ArrayList<SpatialOperation>();// Geometry Operations++ /** Bounding box of the *indexed* shape. */public static final SpatialOperation BBoxIntersects = new SpatialOperation("BBoxIntersects", true, false, false);+ /** Bounding box of the *indexed* shape. */public static final SpatialOperation BBoxWithin = new SpatialOperation("BBoxWithin", true, false, false);public static final SpatialOperation Contains = new SpatialOperation("Contains", true, true, false);public static final SpatialOperation Intersects = new SpatialOperation("Intersects", true, false, false);diff --git a/lucene/spatial/src/test-files/cities-Intersects-BBox.txt b/lucene/spatial/src/test-files/cities-Intersects-BBox.txtnew file mode 100644index 00000000000..36bf9072fe8--- /dev/null+++ b/lucene/spatial/src/test-files/cities-Intersects-BBox.txt@@ -0,0 +1,7 @@+[San Francisco] G5391959 @ Intersects(-122.524918 37.674973 -122.360123 37.817108)+[Wellington] G2179537 @ Intersects(174.711456 -41.360779 174.854279 -41.213837)+[Barcelona] G6544100 G3128760 @ Intersects(2.127228 41.333313 2.226105 41.408844)++++diff --git a/lucene/spatial/src/test-files/cities-IsWithin-BBox.txt b/lucene/spatial/src/test-files/cities-IsWithin-BBox.txtdeleted file mode 100644index 1df64eace42..00000000000--- a/lucene/spatial/src/test-files/cities-IsWithin-BBox.txt+++ /dev/null@@ -1,7 +0,0 @@-[San Francisco] G5391959 @ IsWithin(-122.524918 37.674973 -122.360123 37.817108)-[Wellington] G2179537 @ IsWithin(174.711456 -41.360779 174.854279 -41.213837)-[Barcelona] G6544100 G3128760 @ IsWithin(2.127228 41.333313 2.226105 41.408844)----diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/PortedSolr3Test.java b/lucene/spatial/src/test/org/apache/lucene/spatial/PortedSolr3Test.javaindex ed72999b73c..00e261376e2 100644--- a/lucene/spatial/src/test/org/apache/lucene/spatial/PortedSolr3Test.java+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/PortedSolr3Test.java@@ -192,7 +192,6 @@ public class PortedSolr3Test extends StrategyTestCase {addDocument(newDoc(idStr,shape));}- @SuppressWarnings("unchecked")private Document newDoc(String id, Shape shape) {Document doc = new Document();doc.add(new StringField("id", id, Field.Store.YES));@@ -205,17 +204,19 @@ public class PortedSolr3Test extends StrategyTestCase {}private void checkHitsCircle(String ptStr, double distKM, int assertNumFound, int... assertIds) {- _checkHits(SpatialOperation.Intersects, ptStr, distKM, assertNumFound, assertIds);+ _checkHits(false, ptStr, distKM, assertNumFound, assertIds);}private void checkHitsBBox(String ptStr, double distKM, int assertNumFound, int... assertIds) {- _checkHits(SpatialOperation.BBoxIntersects, ptStr, distKM, assertNumFound, assertIds);+ _checkHits(true, ptStr, distKM, assertNumFound, assertIds);}- @SuppressWarnings("unchecked")- private void _checkHits(SpatialOperation op, String ptStr, double distKM, int assertNumFound, int... assertIds) {+ private void _checkHits(boolean bbox, String ptStr, double distKM, int assertNumFound, int... assertIds) {+ SpatialOperation op = SpatialOperation.Intersects;Point pt = (Point) new ShapeReadWriter(ctx).readShape(ptStr);double distDEG = DistanceUtils.dist2Degrees(distKM, DistanceUtils.EARTH_MEAN_RADIUS_KM);Shape shape = ctx.makeCircle(pt, distDEG);+ if (bbox)+ shape = shape.getBoundingBox();SpatialArgs args = new SpatialArgs(op,shape);//args.setDistPrecision(0.025);diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/StrategyTestCase.java b/lucene/spatial/src/test/org/apache/lucene/spatial/StrategyTestCase.javaindex 3b983fe781a..ab056f919c3 100644--- a/lucene/spatial/src/test/org/apache/lucene/spatial/StrategyTestCase.java+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/StrategyTestCase.java@@ -27,7 +27,6 @@ import org.apache.lucene.document.Document;import org.apache.lucene.document.Field;import org.apache.lucene.document.StoredField;import org.apache.lucene.document.StringField;-import org.apache.lucene.index.IndexableField;import org.apache.lucene.spatial.query.SpatialArgsParser;import org.junit.Assert;@@ -52,7 +51,7 @@ public abstract class StrategyTestCase extends SpatialTestCase {public static final String QTEST_States_IsWithin_BBox = "states-IsWithin-BBox.txt";public static final String QTEST_States_Intersects_BBox = "states-Intersects-BBox.txt";- public static final String QTEST_Cities_IsWithin_BBox = "cities-IsWithin-BBox.txt";+ public static final String QTEST_Cities_Intersects_BBox = "cities-Intersects-BBox.txt";public static final String QTEST_Simple_Queries_BBox = "simple-Queries-BBox.txt";private Logger log = Logger.getLogger(getClass().getName());diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/TestTestFramework.java b/lucene/spatial/src/test/org/apache/lucene/spatial/TestTestFramework.javaindex 3991264a507..55237efd798 100644--- a/lucene/spatial/src/test/org/apache/lucene/spatial/TestTestFramework.java+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/TestTestFramework.java@@ -17,7 +17,6 @@ package org.apache.lucene.spatial;* limitations under the License.*/-import com.spatial4j.core.context.SpatialContext;import com.spatial4j.core.context.SpatialContext;import com.spatial4j.core.shape.Rectangle;import org.apache.lucene.spatial.query.SpatialArgsParser;@@ -40,7 +39,7 @@ public class TestTestFramework extends LuceneTestCase {@Testpublic void testQueries() throws IOException {- String name = StrategyTestCase.QTEST_Cities_IsWithin_BBox;+ String name = StrategyTestCase.QTEST_Cities_Intersects_BBox;InputStream in = getClass().getClassLoader().getResourceAsStream(name);SpatialContext ctx = SpatialContext.GEO;@@ -57,7 +56,7 @@ public class TestTestFramework extends LuceneTestCase {Assert.assertEquals( 1, sf.ids.size() );Assert.assertTrue( sf.ids.get(0).equals( "G5391959" ) );Assert.assertTrue( sf.args.getShape() instanceof Rectangle);- Assert.assertEquals( SpatialOperation.IsWithin, sf.args.getOperation() );+ Assert.assertEquals( SpatialOperation.Intersects, sf.args.getOperation() );}}diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/bbox/TestBBoxStrategy.java b/lucene/spatial/src/test/org/apache/lucene/spatial/bbox/TestBBoxStrategy.javaindex e521b1b3e1f..f15f36fc16e 100644--- a/lucene/spatial/src/test/org/apache/lucene/spatial/bbox/TestBBoxStrategy.java+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/bbox/TestBBoxStrategy.java@@ -51,10 +51,10 @@ public class TestBBoxStrategy extends StrategyTestCase {}@Test- public void testCitiesWithinBBox() throws IOException {+ public void testCitiesIntersectsBBox() throws IOException {getAddAndVerifyIndexedDocuments(DATA_WORLD_CITIES_POINTS);- executeQueries(SpatialMatchConcern.FILTER, QTEST_Cities_IsWithin_BBox);+ executeQueries(SpatialMatchConcern.FILTER, QTEST_Cities_Intersects_BBox);}}diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/TestRecursivePrefixTreeStrategy.java b/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/TestRecursivePrefixTreeStrategy.javaindex 995fb96a8e4..49d9e459889 100644--- a/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/TestRecursivePrefixTreeStrategy.java+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/TestRecursivePrefixTreeStrategy.java@@ -61,7 +61,7 @@ public class TestRecursivePrefixTreeStrategy extends StrategyTestCase {//execute queries for each prefix grid scan levelfor(int i = 0; i <= maxLength; i++) {((RecursivePrefixTreeStrategy)strategy).setPrefixGridScanLevel(i);- executeQueries(SpatialMatchConcern.FILTER, QTEST_Cities_IsWithin_BBox);+ executeQueries(SpatialMatchConcern.FILTER, QTEST_Cities_Intersects_BBox);}}diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/TestTermQueryPrefixGridStrategy.java b/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/TestTermQueryPrefixGridStrategy.javaindex b74746b2ca7..b56dff9d947 100644--- a/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/TestTermQueryPrefixGridStrategy.java+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/TestTermQueryPrefixGridStrategy.java@@ -17,7 +17,6 @@ package org.apache.lucene.spatial.prefix;* limitations under the License.*/-import com.spatial4j.core.context.SpatialContext;import com.spatial4j.core.context.SpatialContext;import com.spatial4j.core.shape.Shape;import org.apache.lucene.document.Document;@@ -55,7 +54,7 @@ public class TestTermQueryPrefixGridStrategy extends SpatialTestCase {SpatialArgsParser spatialArgsParser = new SpatialArgsParser();// TODO... use a non polygon query// SpatialArgs spatialArgs = spatialArgsParser.parse(-// "IsWithin(POLYGON((-127.00390625 39.8125,-112.765625 39.98828125,-111.53515625 31.375,-125.94921875 30.14453125,-127.00390625 39.8125)))",+// "Intersects(POLYGON((-127.00390625 39.8125,-112.765625 39.98828125,-111.53515625 31.375,-125.94921875 30.14453125,-127.00390625 39.8125)))",// new SimpleSpatialContext());// Query query = prefixGridStrategy.makeQuery(spatialArgs, fieldInfo);diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/vector/TestTwoDoublesStrategy.java b/lucene/spatial/src/test/org/apache/lucene/spatial/vector/TestTwoDoublesStrategy.javaindex bac233a8bf6..ff8a54c9275 100644--- a/lucene/spatial/src/test/org/apache/lucene/spatial/vector/TestTwoDoublesStrategy.java+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/vector/TestTwoDoublesStrategy.java@@ -58,8 +58,8 @@ public class TestTwoDoublesStrategy extends StrategyTestCase {}@Test- public void testCitiesWithinBBox() throws IOException {+ public void testCitiesIntersectsBBox() throws IOException {getAddAndVerifyIndexedDocuments(DATA_WORLD_CITIES_POINTS);- executeQueries(SpatialMatchConcern.FILTER, QTEST_Cities_IsWithin_BBox);+ executeQueries(SpatialMatchConcern.FILTER, QTEST_Cities_Intersects_BBox);}}