mirror of https://github.com/apache/lucene.git
LUCENE-9470: make TestXYMultiPolygonShapeQueries more resilient for CONTAINS queries (#1776)
This commit is contained in:
parent
12dab0f80e
commit
7da15706da
|
@ -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 =======================
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue