Apache Lucene open-source search software
fix LatLonShapeBoundingBoxQuery to not round min Y above max Y value
Nicholas Knizedc6019c54e93
diff --git a/lucene/sandbox/src/java/org/apache/lucene/document/LatLonShapeBoundingBoxQuery.java b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonShapeBoundingBoxQuery.javaindex b4f7f4bb0ec..ebbdeed88de 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 boxesdiff --git a/lucene/sandbox/src/test/org/apache/lucene/document/BaseLatLonShapeTestCase.java b/lucene/sandbox/src/test/org/apache/lucene/document/BaseLatLonShapeTestCase.javaindex 942979bcce9..e8ea640c1d1 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 deletedexpected = false;@@ -333,7 +335,11 @@ public abstract class BaseLatLonShapeTestCase extends LuceneTestCase {// then do not use encodeCeilqMinLon = 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) {diff --git a/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonPointShapeQueries.java b/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonPointShapeQueries.javaindex 96b026c0c56..6020617207b 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 triangleRelation r = tree.relateTriangle(lon, lat, lon, lat, lon, lat);if (queryRelation == QueryRelation.WITHIN) {diff --git a/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonShape.java b/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonShape.javaindex 9a125bacdae..d3ab8a68c85 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);+ }}