You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by iv...@apache.org on 2020/09/09 14:08:07 UTC

[lucene-solr] branch branch_8x updated: LUCENE-9470: make TestXYMultiPolygonShapeQueries more resilient for CONTAINS queries (#1776)

This is an automated email from the ASF dual-hosted git repository.

ivera pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/branch_8x by this push:
     new 8ac53aa  LUCENE-9470: make TestXYMultiPolygonShapeQueries more resilient for CONTAINS queries (#1776)
8ac53aa is described below

commit 8ac53aa6bc21d460b69866f64dd24f65f304ced6
Author: Ignacio Vera <iv...@apache.org>
AuthorDate: Wed Sep 9 16:06:25 2020 +0200

    LUCENE-9470: make TestXYMultiPolygonShapeQueries more resilient for CONTAINS queries (#1776)
---
 lucene/CHANGES.txt                                  |  1 +
 .../document/TestXYMultiPolygonShapeQueries.java    | 21 ++++++++++++++++++---
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index b436f68..ea9c08f 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -80,6 +80,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 6803af9..92d27f8 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