Apache Lucene open-source search software
LUCENE-9275: make TestLatLonMultiPolygonShapeQueries more resilient for CONTAINS queries (#1345)
Ignacio Veraaaf08c9c4d9c
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 195da2ec5ff..8222296b46b 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -153,6 +153,8 @@ Other* LUCENE-9270: Update Javadoc about normalizeEntry in the Kuromoji DictionaryBuilder. (Namgyu Kim)+* LUCENE-9275: Make TestLatLonMultiPolygonShapeQueries more resilient for CONTAINS queries. (Ignacio Vera)+======================= Lucene 8.5.0 =======================API Changesdiff --git a/lucene/core/src/test/org/apache/lucene/document/TestLatLonMultiPolygonShapeQueries.java b/lucene/core/src/test/org/apache/lucene/document/TestLatLonMultiPolygonShapeQueries.javaindex b1b180d871e..8732d5f3f4b 100644--- a/lucene/core/src/test/org/apache/lucene/document/TestLatLonMultiPolygonShapeQueries.java+++ b/lucene/core/src/test/org/apache/lucene/document/TestLatLonMultiPolygonShapeQueries.java@@ -98,6 +98,7 @@ public class TestLatLonMultiPolygonShapeQueries extends BaseLatLonShapeTestCaseprotected class MultiPolygonValidator extends Validator {TestLatLonPolygonShapeQueries.PolygonValidator POLYGONVALIDATOR;+MultiPolygonValidator(Encoder encoder) {super(encoder);POLYGONVALIDATOR = new TestLatLonPolygonShapeQueries.PolygonValidator(encoder);@@ -112,7 +113,7 @@ public class TestLatLonMultiPolygonShapeQueries extends BaseLatLonShapeTestCase@Overridepublic boolean testBBoxQuery(double minLat, double maxLat, double minLon, double maxLon, Object shape) {- Polygon[] polygons = (Polygon[])shape;+ Polygon[] polygons = (Polygon[]) shape;for (Polygon p : polygons) {boolean b = POLYGONVALIDATOR.testBBoxQuery(minLat, maxLat, minLon, maxLon, p);if (b == true && queryRelation == QueryRelation.INTERSECTS) {@@ -130,7 +131,10 @@ public class TestLatLonMultiPolygonShapeQueries extends BaseLatLonShapeTestCase@Overridepublic boolean testComponentQuery(Component2D query, Object shape) {- Polygon[] polygons = (Polygon[])shape;+ Polygon[] polygons = (Polygon[]) shape;+ if (queryRelation == QueryRelation.CONTAINS) {+ return testWithinPolygon(query, polygons);+ }for (Polygon p : polygons) {boolean b = POLYGONVALIDATOR.testComponentQuery(query, p);if (b == true && queryRelation == QueryRelation.INTERSECTS) {@@ -145,6 +149,19 @@ public class TestLatLonMultiPolygonShapeQueries extends BaseLatLonShapeTestCase}return queryRelation != QueryRelation.INTERSECTS && queryRelation != QueryRelation.CONTAINS;}++ private boolean testWithinPolygon(Component2D query, Polygon[] polygons) {+ Component2D.WithinRelation answer = Component2D.WithinRelation.DISJOINT;+ for (Polygon p : polygons) {+ Component2D.WithinRelation relation = POLYGONVALIDATOR.testWithinPolygon(query, p);+ if (relation == Component2D.WithinRelation.NOTWITHIN) {+ return false;+ } else if (relation == Component2D.WithinRelation.CANDIDATE) {+ answer = relation;+ }+ }+ return answer == Component2D.WithinRelation.CANDIDATE;+ }}@Slowdiff --git a/lucene/core/src/test/org/apache/lucene/document/TestLatLonPolygonShapeQueries.java b/lucene/core/src/test/org/apache/lucene/document/TestLatLonPolygonShapeQueries.javaindex 23c6d3a7a87..3a270a3622a 100644--- a/lucene/core/src/test/org/apache/lucene/document/TestLatLonPolygonShapeQueries.java+++ b/lucene/core/src/test/org/apache/lucene/document/TestLatLonPolygonShapeQueries.java@@ -74,7 +74,7 @@ public class TestLatLonPolygonShapeQueries extends BaseLatLonShapeTestCase {public boolean testComponentQuery(Component2D query, Object o) {Polygon shape = (Polygon) o;if (queryRelation == QueryRelation.CONTAINS) {- return testWithinPolygon(query, shape);+ return testWithinPolygon(query, shape) == Component2D.WithinRelation.CANDIDATE;}List<Tessellator.Triangle> tessellation = Tessellator.tessellate(shape);for (Tessellator.Triangle t : tessellation) {@@ -93,7 +93,8 @@ public class TestLatLonPolygonShapeQueries extends BaseLatLonShapeTestCase {return queryRelation == QueryRelation.INTERSECTS ? false : true;}- private boolean testWithinPolygon(Component2D component2D, Polygon shape) {++ protected Component2D.WithinRelation testWithinPolygon(Component2D component2D, Polygon shape) {List<Tessellator.Triangle> tessellation = Tessellator.tessellate(shape);Component2D.WithinRelation answer = Component2D.WithinRelation.DISJOINT;for (Tessellator.Triangle t : tessellation) {@@ -104,12 +105,12 @@ public class TestLatLonPolygonShapeQueries extends BaseLatLonShapeTestCase {encoder.decodeX(qTriangle.bX), encoder.decodeY(qTriangle.bY), qTriangle.bc,encoder.decodeX(qTriangle.cX), encoder.decodeY(qTriangle.cY), qTriangle.ca);if (relation == Component2D.WithinRelation.NOTWITHIN) {- return false;+ return relation;} else if (relation == Component2D.WithinRelation.CANDIDATE) {answer = Component2D.WithinRelation.CANDIDATE;}}- return answer == Component2D.WithinRelation.CANDIDATE;+ return answer;}}