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 2014/08/20 19:18:37 UTC

svn commit: r1619165 - in /lucene/dev/branches/branch_4x: ./ lucene/ lucene/spatial/ lucene/spatial/src/test/org/apache/lucene/spatial/bbox/ lucene/spatial/src/test/org/apache/lucene/spatial/bbox/TestBBoxStrategy.java

Author: dsmiley
Date: Wed Aug 20 17:18:37 2014
New Revision: 1619165

URL: http://svn.apache.org/r1619165
Log:
LUCENE-5714: TestBBoxStrategy work-around for Spatial4j Rect bug #85

Modified:
    lucene/dev/branches/branch_4x/   (props changed)
    lucene/dev/branches/branch_4x/lucene/   (props changed)
    lucene/dev/branches/branch_4x/lucene/spatial/   (props changed)
    lucene/dev/branches/branch_4x/lucene/spatial/src/test/org/apache/lucene/spatial/bbox/   (props changed)
    lucene/dev/branches/branch_4x/lucene/spatial/src/test/org/apache/lucene/spatial/bbox/TestBBoxStrategy.java

Modified: lucene/dev/branches/branch_4x/lucene/spatial/src/test/org/apache/lucene/spatial/bbox/TestBBoxStrategy.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/spatial/src/test/org/apache/lucene/spatial/bbox/TestBBoxStrategy.java?rev=1619165&r1=1619164&r2=1619165&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/spatial/src/test/org/apache/lucene/spatial/bbox/TestBBoxStrategy.java (original)
+++ lucene/dev/branches/branch_4x/lucene/spatial/src/test/org/apache/lucene/spatial/bbox/TestBBoxStrategy.java Wed Aug 20 17:18:37 2014
@@ -25,8 +25,10 @@ import com.spatial4j.core.shape.Rectangl
 import com.spatial4j.core.shape.Shape;
 import com.spatial4j.core.shape.impl.RectangleImpl;
 import org.apache.lucene.document.FieldType;
+import org.apache.lucene.search.Query;
 import org.apache.lucene.spatial.SpatialMatchConcern;
 import org.apache.lucene.spatial.prefix.RandomSpatialOpStrategyTestCase;
+import org.apache.lucene.spatial.query.SpatialArgs;
 import org.apache.lucene.spatial.query.SpatialOperation;
 import org.apache.lucene.spatial.util.ShapeAreaValueSource;
 import org.junit.Ignore;
@@ -53,19 +55,27 @@ public class TestBBoxStrategy extends Ra
     int worldHeight = (int) Math.round(world.getHeight());
     int deltaTop = nextIntInclusive(worldHeight);
     int deltaBottom = nextIntInclusive(worldHeight - deltaTop);
-    if (ctx.isGeo() && (deltaLeft != 0 || deltaRight != 0)) {
-      //if geo & doesn't world-wrap, we shift randomly to potentially cross dateline
-      int shift = nextIntInclusive(360);
-      return ctx.makeRectangle(
-          DistanceUtils.normLonDEG(world.getMinX() + deltaLeft + shift),
-          DistanceUtils.normLonDEG(world.getMaxX() - deltaRight + shift),
-          world.getMinY() + deltaBottom, world.getMaxY() - deltaTop);
-    } else {
-      return ctx.makeRectangle(
-          world.getMinX() + deltaLeft, world.getMaxX() - deltaRight,
-          world.getMinY() + deltaBottom, world.getMaxY() - deltaTop);
-    }
 
+    double rectMinX = world.getMinX() + deltaLeft;
+    double rectMaxX = world.getMaxX() - deltaRight;
+    if (ctx.isGeo()) {
+      int shift = 0;
+      if ((deltaLeft != 0 || deltaRight != 0)) {
+        //if geo & doesn't world-wrap, we shift randomly to potentially cross dateline
+        shift = nextIntInclusive(360);
+      }
+      rectMinX = DistanceUtils.normLonDEG(rectMinX + shift);
+      rectMaxX = DistanceUtils.normLonDEG(rectMaxX + shift);
+      if (rectMinX == 180 && rectMaxX == 180) {
+        // Work-around for https://github.com/spatial4j/spatial4j/issues/85
+        rectMinX = -180;
+        rectMaxX = -180;
+      }
+    }
+    return ctx.makeRectangle(
+        rectMinX,
+        rectMaxX,
+        world.getMinY() + deltaBottom, world.getMaxY() - deltaTop);
   }
 
   /** next int, inclusive, rounds to multiple of 10 if given evenly divisible. */
@@ -158,6 +168,33 @@ public class TestBBoxStrategy extends Ra
         ctx.makeRectangle(170, -170, -10, 10), true);
   }
 
+  /** See https://github.com/spatial4j/spatial4j/issues/85 */
+  @Test
+  public void testAlongDatelineOppositeSign() throws IOException {
+    // Due to Spatial4j bug #85, we can't simply do:
+    //    testOperation(indexedShape,
+    //        SpatialOperation.IsWithin,
+    //        queryShape, true);
+
+    //both on dateline but expressed using opposite signs
+    setupGeo();
+    final Rectangle indexedShape = ctx.makeRectangle(180, 180, -10, 10);
+    final Rectangle queryShape = ctx.makeRectangle(-180, -180, -20, 20);
+    final SpatialOperation operation = SpatialOperation.IsWithin;
+    final boolean match = true;//yes it is within
+
+    //the rest is super.testOperation without leading assert:
+
+    adoc("0", indexedShape);
+    commit();
+    Query query = strategy.makeQuery(new SpatialArgs(operation, queryShape));
+    SearchResults got = executeQuery(query, 1);
+    assert got.numFound <= 1 : "unclean test env";
+    if ((got.numFound == 1) != match)
+      fail(operation+" I:" + indexedShape + " Q:" + queryShape);
+    deleteAll();//clean up after ourselves
+  }
+
   private void setupGeo() {
     this.ctx = SpatialContext.GEO;
     this.strategy = new BBoxStrategy(ctx, "bbox");