Apache Lucene open-source search software
LUCENE-7660: LatLonPointDistanceQuery could skip distance computations more often.
Adrien Grand076662d1b234
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 0be102cadf7..6a0d17ddeaa 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -131,6 +131,10 @@ Optimizations* LUCENE-7661: Speed up for LatLonPointInPolygonQuery by pre-computing therelation of the polygon with a grid. (Adrien Grand)+* LUCENE-7660: Speed up LatLonPointDistanceQuery by improving the detection of+ whether BKD cells are entirely within the distance close to the dateline.+ (Adrien Grand)+Build* LUCENE-7651: Fix Javadocs build for Java 8u121 by injecting "Google Codediff --git a/lucene/core/src/java/org/apache/lucene/geo/GeoUtils.java b/lucene/core/src/java/org/apache/lucene/geo/GeoUtils.javaindex defcb4812bc..aaca549ce15 100644--- a/lucene/core/src/java/org/apache/lucene/geo/GeoUtils.java+++ b/lucene/core/src/java/org/apache/lucene/geo/GeoUtils.java@@ -152,7 +152,7 @@ public final class GeoUtils {}}- if (maxLon - lon < 90 && lon - minLon < 90 &&+ if (within90LonDegrees(lon, minLon, maxLon) &&SloppyMath.haversinSortKey(lat, lon, minLat, minLon) <= distanceSortKey &&SloppyMath.haversinSortKey(lat, lon, minLat, maxLon) <= distanceSortKey &&SloppyMath.haversinSortKey(lat, lon, maxLat, minLon) <= distanceSortKey &&@@ -163,4 +163,15 @@ public final class GeoUtils {return Relation.CELL_CROSSES_QUERY;}++ /** Return whether all points of {@code [minLon,maxLon]} are within 90 degrees of {@code lon}. */+ static boolean within90LonDegrees(double lon, double minLon, double maxLon) {+ if (maxLon <= lon - 180) {+ lon -= 360;+ } else if (minLon >= lon + 180) {+ lon += 360;+ }+ return maxLon - lon < 90 && lon - minLon < 90;+ }+}diff --git a/lucene/core/src/test/org/apache/lucene/geo/TestGeoUtils.java b/lucene/core/src/test/org/apache/lucene/geo/TestGeoUtils.javaindex 2cfb2f84002..3d95a6d1a56 100644--- a/lucene/core/src/test/org/apache/lucene/geo/TestGeoUtils.java+++ b/lucene/core/src/test/org/apache/lucene/geo/TestGeoUtils.java@@ -293,4 +293,16 @@ public class TestGeoUtils extends LuceneTestCase {return false;}++ public void testWithin90LonDegrees() {+ assertTrue(GeoUtils.within90LonDegrees(0, -80, 80));+ assertFalse(GeoUtils.within90LonDegrees(0, -100, 80));+ assertFalse(GeoUtils.within90LonDegrees(0, -80, 100));++ assertTrue(GeoUtils.within90LonDegrees(-150, 140, 170));+ assertFalse(GeoUtils.within90LonDegrees(-150, 120, 150));++ assertTrue(GeoUtils.within90LonDegrees(150, -170, -140));+ assertFalse(GeoUtils.within90LonDegrees(150, -150, -120));+ }}