Apache Lucene open-source search software
LUCENE-4166: Fixed bad type checking of Circle shapes in TwoDoublesStrategy
Christopher John Malec4b08cf35c48
diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/vector/TwoDoublesStrategy.java b/lucene/spatial/src/java/org/apache/lucene/spatial/vector/TwoDoublesStrategy.javaindex 559b840422b..1276e0c82b2 100644--- a/lucene/spatial/src/java/org/apache/lucene/spatial/vector/TwoDoublesStrategy.java+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/vector/TwoDoublesStrategy.java@@ -113,10 +113,13 @@ public class TwoDoublesStrategy extends SpatialStrategy<TwoDoublesFieldInfo> {public Query makeQuery(SpatialArgs args, TwoDoublesFieldInfo fieldInfo) {// For starters, just limit the bboxShape shape = args.getShape();- if (!(shape instanceof Rectangle)) {- throw new InvalidShapeException("A rectangle is the only supported shape (so far), not "+shape.getClass());//TODO+ if (!(shape instanceof Rectangle || shape instanceof Circle)) {+ throw new InvalidShapeException("Only Rectangles and Circles are currently supported, " ++ "found [" + shape.getClass() + "]");//TODO}- Rectangle bbox = (Rectangle) shape;++ Rectangle bbox = shape.getBoundingBox();+if (bbox.getCrossesDateLine()) {throw new UnsupportedOperationException( "Crossing dateline not yet supported" );}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 d6f65715739..6dd6ef6e32a 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@@ -18,7 +18,15 @@package org.apache.lucene.spatial.vector;import com.spatial4j.core.context.simple.SimpleSpatialContext;+import com.spatial4j.core.exception.InvalidShapeException;+import com.spatial4j.core.query.SpatialArgs;+import com.spatial4j.core.query.SpatialOperation;+import com.spatial4j.core.shape.Circle;+import com.spatial4j.core.shape.Point;+import com.spatial4j.core.shape.simple.CircleImpl;+import com.spatial4j.core.shape.simple.PointImpl;import org.apache.lucene.search.FieldCache;+import org.apache.lucene.search.Query;import org.apache.lucene.spatial.SpatialMatchConcern;import org.apache.lucene.spatial.StrategyTestCase;import org.apache.lucene.spatial.util.NumericFieldInfo;@@ -39,6 +47,22 @@ public class TestTwoDoublesStrategy extends StrategyTestCase<TwoDoublesFieldInfothis.fieldInfo = new TwoDoublesFieldInfo(getClass().getSimpleName());}+ @Test+ public void testCircleShapeSupport() {+ Circle circle = new CircleImpl(new PointImpl(0, 0), 10, this.ctx);+ SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, circle);+ Query query = this.strategy.makeQuery(args, this.fieldInfo);++ assertNotNull(query);+ }++ @Test(expected = InvalidShapeException.class)+ public void testInvalidQueryShape() {+ Point point = new PointImpl(0, 0);+ SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, point);+ this.strategy.makeQuery(args, this.fieldInfo);+ }+@Testpublic void testCitiesWithinBBox() throws IOException {getAddAndVerifyIndexedDocuments(DATA_WORLD_CITIES_POINTS);