lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nkn...@apache.org
Subject lucene-solr:master: fix LatLonShapeBoundingBoxQuery to not round min Y above max Y value
Date Thu, 08 Nov 2018 23:58:45 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/master 73005d482 -> dc6019c54


fix LatLonShapeBoundingBoxQuery to not round min Y above max Y value


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/dc6019c5
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/dc6019c5
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/dc6019c5

Branch: refs/heads/master
Commit: dc6019c54e93d38fe89302e9d42fe3e596440e08
Parents: 73005d4
Author: Nicholas Knize <nknize@gmail.com>
Authored: Thu Nov 8 16:27:37 2018 -0600
Committer: Nicholas Knize <nknize@gmail.com>
Committed: Thu Nov 8 16:34:54 2018 -0600

----------------------------------------------------------------------
 .../document/LatLonShapeBoundingBoxQuery.java   |  9 ++++++--
 .../document/BaseLatLonShapeTestCase.java       |  8 ++++++-
 .../document/TestLatLonPointShapeQueries.java   |  9 ++------
 .../apache/lucene/document/TestLatLonShape.java | 22 ++++++++++++++++++++
 4 files changed, 38 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/dc6019c5/lucene/sandbox/src/java/org/apache/lucene/document/LatLonShapeBoundingBoxQuery.java
----------------------------------------------------------------------
diff --git a/lucene/sandbox/src/java/org/apache/lucene/document/LatLonShapeBoundingBoxQuery.java
b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonShapeBoundingBoxQuery.java
index b4f7f4b..ebbdeed 100644
--- a/lucene/sandbox/src/java/org/apache/lucene/document/LatLonShapeBoundingBoxQuery.java
+++ b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonShapeBoundingBoxQuery.java
@@ -57,8 +57,13 @@ final class LatLonShapeBoundingBoxQuery extends LatLonShapeQuery {
     this.bbox = new byte[4 * LatLonShape.BYTES];
     int minXenc = encodeLongitudeCeil(minLon);
     int maxXenc = encodeLongitude(maxLon);
-    this.minY = encodeLatitudeCeil(minLat);
-    this.maxY = encodeLatitude(maxLat);
+    int minYenc = encodeLatitudeCeil(minLat);
+    int maxYenc = encodeLatitude(maxLat);
+    if (minYenc > maxYenc) {
+      minYenc = maxYenc;
+    }
+    this.minY = minYenc;
+    this.maxY = maxYenc;
 
     if (minLon > maxLon == true) {
       // crossing dateline is split into east/west boxes

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/dc6019c5/lucene/sandbox/src/test/org/apache/lucene/document/BaseLatLonShapeTestCase.java
----------------------------------------------------------------------
diff --git a/lucene/sandbox/src/test/org/apache/lucene/document/BaseLatLonShapeTestCase.java
b/lucene/sandbox/src/test/org/apache/lucene/document/BaseLatLonShapeTestCase.java
index 942979b..e8ea640 100644
--- a/lucene/sandbox/src/test/org/apache/lucene/document/BaseLatLonShapeTestCase.java
+++ b/lucene/sandbox/src/test/org/apache/lucene/document/BaseLatLonShapeTestCase.java
@@ -321,6 +321,8 @@ public abstract class BaseLatLonShapeTestCase extends LuceneTestCase {
         boolean expected;
         double qMinLon = quantizeLonCeil(rect.minLon);
         double qMaxLon = quantizeLon(rect.maxLon);
+        double qMinLat = quantizeLatCeil(rect.minLat);
+        double qMaxLat = quantizeLat(rect.maxLat);
         if (liveDocs != null && liveDocs.get(docID) == false) {
           // document is deleted
           expected = false;
@@ -333,7 +335,11 @@ public abstract class BaseLatLonShapeTestCase extends LuceneTestCase
{
             // then do not use encodeCeil
             qMinLon = quantizeLon(rect.minLon);
           }
-          expected = getValidator(queryRelation).testBBoxQuery(quantizeLatCeil(rect.minLat),
quantizeLat(rect.maxLat), qMinLon, qMaxLon, shapes[id]);
+
+          if (qMinLat > qMaxLat) {
+            qMinLat = quantizeLat(rect.maxLat);
+          }
+          expected = getValidator(queryRelation).testBBoxQuery(qMinLat, qMaxLat, qMinLon,
qMaxLon, shapes[id]);
         }
 
         if (hits.get(docID) != expected) {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/dc6019c5/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonPointShapeQueries.java
----------------------------------------------------------------------
diff --git a/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonPointShapeQueries.java
b/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonPointShapeQueries.java
index 96b026c..6020617 100644
--- a/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonPointShapeQueries.java
+++ b/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonPointShapeQueries.java
@@ -25,11 +25,6 @@ import org.apache.lucene.geo.Line2D;
 import org.apache.lucene.geo.Polygon2D;
 import org.apache.lucene.index.PointValues.Relation;
 
-import static org.apache.lucene.geo.GeoEncodingUtils.decodeLatitude;
-import static org.apache.lucene.geo.GeoEncodingUtils.decodeLongitude;
-import static org.apache.lucene.geo.GeoEncodingUtils.encodeLatitude;
-import static org.apache.lucene.geo.GeoEncodingUtils.encodeLongitude;
-
 /** random bounding box and polygon query tests for random generated {@code latitude, longitude}
points */
 public class TestLatLonPointShapeQueries extends BaseLatLonShapeTestCase {
 
@@ -105,8 +100,8 @@ public class TestLatLonPointShapeQueries extends BaseLatLonShapeTestCase
{
     }
 
     private boolean testPoint(EdgeTree tree, Point p) {
-      double lat = decodeLatitude(encodeLatitude(p.lat));
-      double lon = decodeLongitude(encodeLongitude(p.lon));
+      double lat = quantizeLat(p.lat);
+      double lon = quantizeLon(p.lon);
       // for consistency w/ the query we test the point as a triangle
       Relation r = tree.relateTriangle(lon, lat, lon, lat, lon, lat);
       if (queryRelation == QueryRelation.WITHIN) {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/dc6019c5/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonShape.java
----------------------------------------------------------------------
diff --git a/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonShape.java b/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonShape.java
index 9a125ba..d3ab8a6 100644
--- a/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonShape.java
+++ b/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonShape.java
@@ -223,4 +223,26 @@ public class TestLatLonShape extends LuceneTestCase {
 
     IOUtils.close(reader, dir);
   }
+
+  public void testPointIndexAndQuery() throws Exception {
+    Directory dir = newDirectory();
+    RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
+    Document document = new Document();
+    BaseLatLonShapeTestCase.Point p = (BaseLatLonShapeTestCase.Point) BaseLatLonShapeTestCase.ShapeType.POINT.nextShape();
+    Field[] fields = LatLonShape.createIndexableFields(FIELDNAME, p.lat, p.lon);
+    for (Field f : fields) {
+      document.add(f);
+    }
+    writer.addDocument(document);
+
+    //// search
+    IndexReader r = writer.getReader();
+    writer.close();
+    IndexSearcher s = newSearcher(r);
+
+    // search by same point
+    Query q = LatLonShape.newBoxQuery(FIELDNAME, QueryRelation.INTERSECTS, p.lat, p.lat,
p.lon, p.lon);
+    assertEquals(1, s.count(q));
+    IOUtils.close(r, dir);
+  }
 }


Mime
View raw message