You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ch...@apache.org on 2012/06/28 05:00:21 UTC

svn commit: r1354804 - in /lucene/dev/branches/branch_4x/lucene/spatial/src: java/org/apache/lucene/spatial/vector/TwoDoublesStrategy.java test/org/apache/lucene/spatial/vector/TestTwoDoublesStrategy.java

Author: chrism
Date: Thu Jun 28 03:00:20 2012
New Revision: 1354804

URL: http://svn.apache.org/viewvc?rev=1354804&view=rev
Log:
LUCENE-4166: Fixed bad type checking of Circle shapes in TwoDoublesStrategy

Modified:
    lucene/dev/branches/branch_4x/lucene/spatial/src/java/org/apache/lucene/spatial/vector/TwoDoublesStrategy.java
    lucene/dev/branches/branch_4x/lucene/spatial/src/test/org/apache/lucene/spatial/vector/TestTwoDoublesStrategy.java

Modified: lucene/dev/branches/branch_4x/lucene/spatial/src/java/org/apache/lucene/spatial/vector/TwoDoublesStrategy.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/spatial/src/java/org/apache/lucene/spatial/vector/TwoDoublesStrategy.java?rev=1354804&r1=1354803&r2=1354804&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/spatial/src/java/org/apache/lucene/spatial/vector/TwoDoublesStrategy.java (original)
+++ lucene/dev/branches/branch_4x/lucene/spatial/src/java/org/apache/lucene/spatial/vector/TwoDoublesStrategy.java Thu Jun 28 03:00:20 2012
@@ -113,10 +113,13 @@ public class TwoDoublesStrategy extends 
   public Query makeQuery(SpatialArgs args, TwoDoublesFieldInfo fieldInfo) {
     // For starters, just limit the bbox
     Shape 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" );
     }

Modified: lucene/dev/branches/branch_4x/lucene/spatial/src/test/org/apache/lucene/spatial/vector/TestTwoDoublesStrategy.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/spatial/src/test/org/apache/lucene/spatial/vector/TestTwoDoublesStrategy.java?rev=1354804&r1=1354803&r2=1354804&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/spatial/src/test/org/apache/lucene/spatial/vector/TestTwoDoublesStrategy.java (original)
+++ lucene/dev/branches/branch_4x/lucene/spatial/src/test/org/apache/lucene/spatial/vector/TestTwoDoublesStrategy.java Thu Jun 28 03:00:20 2012
@@ -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;
@@ -40,6 +48,22 @@ public class TestTwoDoublesStrategy exte
   }
 
   @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);
+  }
+
+  @Test
   public void testCitiesWithinBBox() throws IOException {
     getAddAndVerifyIndexedDocuments(DATA_WORLD_CITIES_POINTS);
     executeQueries(SpatialMatchConcern.FILTER, QTEST_Cities_IsWithin_BBox);