LUCENE-9470: make TestXYMultiPolygonShapeQueries more resilient for CONTAINS queries (#1776)

This commit is contained in:
Ignacio Vera 2020-09-09 16:06:25 +02:00 committed by GitHub
parent 12dab0f80e
commit 7da15706da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 3 deletions

View File

@ -250,6 +250,7 @@ Other
* LUCENE-9292: Refactor BKD point configuration into its own class. (Ignacio Vera) * 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 ======================= ======================= Lucene 8.6.2 =======================

View File

@ -101,6 +101,7 @@ public class TestXYMultiPolygonShapeQueries extends BaseXYShapeTestCase {
protected class MultiPolygonValidator extends Validator { protected class MultiPolygonValidator extends Validator {
TestXYPolygonShapeQueries.PolygonValidator POLYGONVALIDATOR; TestXYPolygonShapeQueries.PolygonValidator POLYGONVALIDATOR;
MultiPolygonValidator(Encoder encoder) { MultiPolygonValidator(Encoder encoder) {
super(encoder); super(encoder);
POLYGONVALIDATOR = new TestXYPolygonShapeQueries.PolygonValidator(encoder); POLYGONVALIDATOR = new TestXYPolygonShapeQueries.PolygonValidator(encoder);
@ -121,13 +122,14 @@ public class TestXYMultiPolygonShapeQueries extends BaseXYShapeTestCase {
@Override @Override
public boolean testComponentQuery(Component2D query, Object shape) { 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) { for (XYPolygon p : polygons) {
boolean b = POLYGONVALIDATOR.testComponentQuery(query, p); boolean b = POLYGONVALIDATOR.testComponentQuery(query, p);
if (b == true && queryRelation == QueryRelation.INTERSECTS) { if (b == true && queryRelation == QueryRelation.INTERSECTS) {
return true; return true;
} else if (b == true && queryRelation == QueryRelation.CONTAINS) {
return true;
} else if (b == false && queryRelation == QueryRelation.DISJOINT) { } else if (b == false && queryRelation == QueryRelation.DISJOINT) {
return false; return false;
} else if (b == false && queryRelation == QueryRelation.WITHIN) { } else if (b == false && queryRelation == QueryRelation.WITHIN) {
@ -136,6 +138,19 @@ public class TestXYMultiPolygonShapeQueries extends BaseXYShapeTestCase {
} }
return queryRelation != QueryRelation.INTERSECTS && queryRelation != QueryRelation.CONTAINS; 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 @Slow