fix LatLonShapeBoundingBoxQuery to not round min Y above max Y value

This commit is contained in:
Nicholas Knize 2018-11-08 16:27:37 -06:00
parent 73005d482d
commit dc6019c54e
4 changed files with 38 additions and 10 deletions

View File

@ -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

View File

@ -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) {

View File

@ -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) {

View File

@ -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);
}
}