lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From iv...@apache.org
Subject [lucene-solr] branch branch_8x updated: LUCENE-9275: make TestLatLonMultiPolygonShapeQueries more resilient for CONTAINS queries (#1345)
Date Mon, 23 Mar 2020 06:27:46 GMT
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 c63d281  LUCENE-9275: make TestLatLonMultiPolygonShapeQueries more resilient for
CONTAINS queries (#1345)
c63d281 is described below

commit c63d2813fdbc9fbb64648edfb41fd1e6a7be0070
Author: Ignacio Vera <ivera@apache.org>
AuthorDate: Mon Mar 23 07:26:48 2020 +0100

    LUCENE-9275: make TestLatLonMultiPolygonShapeQueries more resilient for CONTAINS queries
(#1345)
---
 lucene/CHANGES.txt                                  |  2 ++
 .../TestLatLonMultiPolygonShapeQueries.java         | 21 +++++++++++++++++++--
 .../document/TestLatLonPolygonShapeQueries.java     |  9 +++++----
 3 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index b294bac..31be94b 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -55,6 +55,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 Changes
diff --git a/lucene/core/src/test/org/apache/lucene/document/TestLatLonMultiPolygonShapeQueries.java
b/lucene/core/src/test/org/apache/lucene/document/TestLatLonMultiPolygonShapeQueries.java
index b1b180d..8732d5f 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 BaseLatLonShapeTestCase
 
   protected 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
 
     @Override
     public 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
 
     @Override
     public 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;
+    }
   }
 
   @Slow
diff --git a/lucene/core/src/test/org/apache/lucene/document/TestLatLonPolygonShapeQueries.java
b/lucene/core/src/test/org/apache/lucene/document/TestLatLonPolygonShapeQueries.java
index 23c6d3a..3a270a3 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;
     }
   }
 


Mime
View raw message