You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2017/01/30 10:20:50 UTC

[5/6] lucene-solr:branch_6x: LUCENE-7660: LatLonPointDistanceQuery could skip distance computations more often.

LUCENE-7660: LatLonPointDistanceQuery could skip distance computations more often.


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

Branch: refs/heads/branch_6x
Commit: 1332f0f05b265879073f2879b67da9172b7f203b
Parents: d2051e3
Author: Adrien Grand <jp...@gmail.com>
Authored: Mon Jan 30 09:47:51 2017 +0100
Committer: Adrien Grand <jp...@gmail.com>
Committed: Mon Jan 30 11:16:31 2017 +0100

----------------------------------------------------------------------
 lucene/CHANGES.txt                                     |  4 ++++
 .../core/src/java/org/apache/lucene/geo/GeoUtils.java  | 13 ++++++++++++-
 .../src/test/org/apache/lucene/geo/TestGeoUtils.java   | 12 ++++++++++++
 3 files changed, 28 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/1332f0f0/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 1bc5046..e1af086 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -73,6 +73,10 @@ Optimizations
 * LUCENE-7661: Speed up for LatLonPointInPolygonQuery by pre-computing the
   relation 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 Code

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/1332f0f0/lucene/core/src/java/org/apache/lucene/geo/GeoUtils.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/geo/GeoUtils.java b/lucene/core/src/java/org/apache/lucene/geo/GeoUtils.java
index fa6f7a5..3695d01 100644
--- a/lucene/core/src/java/org/apache/lucene/geo/GeoUtils.java
+++ b/lucene/core/src/java/org/apache/lucene/geo/GeoUtils.java
@@ -153,7 +153,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 &&
@@ -164,4 +164,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;
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/1332f0f0/lucene/core/src/test/org/apache/lucene/geo/TestGeoUtils.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/geo/TestGeoUtils.java b/lucene/core/src/test/org/apache/lucene/geo/TestGeoUtils.java
index 2cfb2f8..3d95a6d 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));
+  }
 }