diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 5645f7ca434..0cac671f026 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -250,6 +250,7 @@ Other * LUCENE-9292: Refactor BKD point configuration into its own class. (Ignacio Vera) +* LUCENE-9470: Make TestXYMultiPolygonShapeQueries more resilient for CONTAINS queries. (Ignacio Vera) ======================= Lucene 8.6.2 ======================= diff --git a/lucene/core/src/test/org/apache/lucene/document/TestXYMultiPolygonShapeQueries.java b/lucene/core/src/test/org/apache/lucene/document/TestXYMultiPolygonShapeQueries.java index 6803af95fd5..92d27f83e0e 100644 --- a/lucene/core/src/test/org/apache/lucene/document/TestXYMultiPolygonShapeQueries.java +++ b/lucene/core/src/test/org/apache/lucene/document/TestXYMultiPolygonShapeQueries.java @@ -101,6 +101,7 @@ public class TestXYMultiPolygonShapeQueries extends BaseXYShapeTestCase { protected class MultiPolygonValidator extends Validator { TestXYPolygonShapeQueries.PolygonValidator POLYGONVALIDATOR; + MultiPolygonValidator(Encoder encoder) { super(encoder); POLYGONVALIDATOR = new TestXYPolygonShapeQueries.PolygonValidator(encoder); @@ -121,13 +122,14 @@ public class TestXYMultiPolygonShapeQueries extends BaseXYShapeTestCase { @Override public boolean testComponentQuery(Component2D query, Object shape) { - XYPolygon[] polygons = (XYPolygon[])shape; + XYPolygon[] polygons = (XYPolygon[]) shape; + if (queryRelation == QueryRelation.CONTAINS) { + return testWithinPolygon(query, polygons); + } for (XYPolygon p : polygons) { boolean b = POLYGONVALIDATOR.testComponentQuery(query, p); if (b == true && queryRelation == QueryRelation.INTERSECTS) { return true; - } else if (b == true && queryRelation == QueryRelation.CONTAINS) { - return true; } else if (b == false && queryRelation == QueryRelation.DISJOINT) { return false; } else if (b == false && queryRelation == QueryRelation.WITHIN) { @@ -136,6 +138,19 @@ public class TestXYMultiPolygonShapeQueries extends BaseXYShapeTestCase { } return queryRelation != QueryRelation.INTERSECTS && queryRelation != QueryRelation.CONTAINS; } + + private boolean testWithinPolygon(Component2D query, XYPolygon[] polygons) { + Component2D.WithinRelation answer = Component2D.WithinRelation.DISJOINT; + for (XYPolygon p : polygons) { + Component2D.WithinRelation relation = POLYGONVALIDATOR.testWithinQuery(query, XYShape.createIndexableFields("dummy", p)); + if (relation == Component2D.WithinRelation.NOTWITHIN) { + return false; + } else if (relation == Component2D.WithinRelation.CANDIDATE) { + answer = relation; + } + } + return answer == Component2D.WithinRelation.CANDIDATE; + } } @Slow