Apache Lucene open-source search software
LUCENE-7845: spatial-extras undo optimize; don't consider any rect or circle to be a point
David Smiley6b022c98f9a1
diff --git a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/prefix/PrefixTreeStrategy.java b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/prefix/PrefixTreeStrategy.javaindex 43851c747b7..0716e7881d5 100644--- a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/prefix/PrefixTreeStrategy.java+++ b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/prefix/PrefixTreeStrategy.java@@ -32,9 +32,7 @@ import org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree;import org.apache.lucene.spatial.query.SpatialArgs;import org.apache.lucene.spatial.util.ShapeFieldCacheDistanceValueSource;import org.apache.lucene.util.Bits;-import org.locationtech.spatial4j.shape.Circle;import org.locationtech.spatial4j.shape.Point;-import org.locationtech.spatial4j.shape.Rectangle;import org.locationtech.spatial4j.shape.Shape;/**@@ -208,15 +206,12 @@ public abstract class PrefixTreeStrategy extends SpatialStrategy {return HeatmapFacetCounter.calcFacets(this, context, topAcceptDocs, inputShape, facetLevel, maxCells);}+ /**+ * Returns true if the {@code shape} is a {@link Point}. For custom spatial contexts, it may make sense to+ * have certain other shapes return true.+ * @lucene.experimental+ */protected boolean isPointShape(Shape shape) {- if (shape instanceof Point) {- return true;- } else if (shape instanceof Circle) {- return ((Circle) shape).getRadius() == 0.0;- } else if (shape instanceof Rectangle) {- Rectangle rect = (Rectangle) shape;- return rect.getWidth() == 0.0 && rect.getHeight() == 0.0;- }- return false;+ return shape instanceof Point;}}diff --git a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/prefix/RecursivePrefixTreeStrategy.java b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/prefix/RecursivePrefixTreeStrategy.javaindex 7c792006b0c..819c50460be 100644--- a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/prefix/RecursivePrefixTreeStrategy.java+++ b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/prefix/RecursivePrefixTreeStrategy.java@@ -216,6 +216,7 @@ public class RecursivePrefixTreeStrategy extends PrefixTreeStrategy {cell = cellIterator.next();assert prevLevel < cell.getLevel();}+ assert cell.isLeaf();return new TermQuery(new Term(getFieldName(), cell.getTokenBytesWithLeaf(null)));} else {// Well there could be parent cells. But we can reduce the "scan level" which will be slower for a point query.diff --git a/lucene/spatial-extras/src/test/org/apache/lucene/spatial/prefix/RandomSpatialOpFuzzyPrefixTreeTest.java b/lucene/spatial-extras/src/test/org/apache/lucene/spatial/prefix/RandomSpatialOpFuzzyPrefixTreeTest.javaindex cfc99808c23..c5b145f97c9 100644--- a/lucene/spatial-extras/src/test/org/apache/lucene/spatial/prefix/RandomSpatialOpFuzzyPrefixTreeTest.java+++ b/lucene/spatial-extras/src/test/org/apache/lucene/spatial/prefix/RandomSpatialOpFuzzyPrefixTreeTest.java@@ -164,6 +164,19 @@ public class RandomSpatialOpFuzzyPrefixTreeTest extends StrategyTestCase {assertEquals(1, executeQuery(query, 1).numFound);}+ @Test+ public void testPointsOnlyOptBug() throws IOException {+ setupQuadGrid(8, false);+ setupCtx2D(ctx);+ ((PrefixTreeStrategy) strategy).setPointsOnly(true);+ Point point = ctx.makePoint(86, -127.44362190053255);+ adoc("0", point);+ commit();+ Query query = strategy.makeQuery(new SpatialArgs(SpatialOperation.Intersects,+ ctx.makeRectangle(point, point)));+ assertEquals(1, executeQuery(query, 1).numFound);+ }+/** See LUCENE-5062, {@link ContainsPrefixTreeQuery#multiOverlappingIndexedShapes}. */@Testpublic void testContainsPairOverlap() throws IOException {