You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2016/04/14 18:02:44 UTC

lucene-solr:master: LUCENE-7069: woops, approxBestDistance was way too approximate when the point was inside the cell

Repository: lucene-solr
Updated Branches:
  refs/heads/master 8d5d20134 -> 5238de937


LUCENE-7069: woops, approxBestDistance was way too approximate when the point was inside the cell


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

Branch: refs/heads/master
Commit: 5238de937a84c4de387f0036830811cb3b7d734f
Parents: 8d5d201
Author: Mike McCandless <mi...@apache.org>
Authored: Thu Apr 14 12:05:10 2016 -0400
Committer: Mike McCandless <mi...@apache.org>
Committed: Thu Apr 14 12:05:10 2016 -0400

----------------------------------------------------------------------
 .../apache/lucene/document/NearestNeighbor.java   | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5238de93/lucene/sandbox/src/java/org/apache/lucene/document/NearestNeighbor.java
----------------------------------------------------------------------
diff --git a/lucene/sandbox/src/java/org/apache/lucene/document/NearestNeighbor.java b/lucene/sandbox/src/java/org/apache/lucene/document/NearestNeighbor.java
index 581be46..3b9f302 100644
--- a/lucene/sandbox/src/java/org/apache/lucene/document/NearestNeighbor.java
+++ b/lucene/sandbox/src/java/org/apache/lucene/document/NearestNeighbor.java
@@ -66,7 +66,7 @@ class NearestNeighbor {
       double minLon = decodeLongitude(minPacked, Integer.BYTES);
       double maxLat = decodeLatitude(maxPacked, 0);
       double maxLon = decodeLongitude(maxPacked, Integer.BYTES);
-      return "Cell(readerIndex=" + readerIndex + " lat=" + minLat + " TO " + maxLat + ", lon=" + minLon + " TO " + maxLon + ")";
+      return "Cell(readerIndex=" + readerIndex + " lat=" + minLat + " TO " + maxLat + ", lon=" + minLon + " TO " + maxLon + "; distanceMeters=" + distanceMeters + ")";
     }
   }
 
@@ -88,8 +88,6 @@ class NearestNeighbor {
     // second set of longitude ranges to check (for cross-dateline case)
     private double minLon2 = Double.POSITIVE_INFINITY;
 
-    int pointCheckCount;
-
     public NearestVisitor(PriorityQueue<NearestHit> hitQueue, int topN, double pointLat, double pointLon) {
       this.hitQueue = hitQueue;
       this.topN = topN;
@@ -106,6 +104,7 @@ class NearestNeighbor {
       if (setBottomCounter < 1024 || (setBottomCounter & 0x3F) == 0x3F) {
         NearestHit hit = hitQueue.peek();
         Rectangle box = Rectangle.fromPointDistance(pointLat, pointLon, hit.distanceMeters);
+        //System.out.println("    update bbox to " + box);
         minLat = box.minLat;
         maxLat = box.maxLat;
         if (box.crossesDateline()) {
@@ -145,8 +144,6 @@ class NearestNeighbor {
         return;
       }
 
-      pointCheckCount++;
-
       double distanceMeters = SloppyMath.haversinMeters(pointLat, pointLon, docLatitude, docLongitude);
 
       //System.out.println("    visit docID=" + docID + " distanceMeters=" + distanceMeters + " docLat=" + docLatitude + " docLon=" + docLongitude);
@@ -198,7 +195,7 @@ class NearestNeighbor {
 
   public static NearestHit[] nearest(double pointLat, double pointLon, List<BKDReader> readers, List<Bits> liveDocs, List<Integer> docBases, final int n) throws IOException {
 
-    //System.out.println("NEAREST: r=" + r + " liveDocs=" + liveDocs);
+    //System.out.println("NEAREST: readers=" + readers + " liveDocs=" + liveDocs + " pointLat=" + pointLat + " pointLon=" + pointLon);
     // Holds closest collected points seen so far:
     // TODO: if we used lucene's PQ we could just updateTop instead of poll/offer:
     final PriorityQueue<NearestHit> hitQueue = new PriorityQueue<>(n, new Comparator<NearestHit>() {
@@ -225,16 +222,11 @@ class NearestNeighbor {
     for(int i=0;i<readers.size();i++) {
       BKDReader reader = readers.get(i);
       byte[] minPackedValue = reader.getMinPackedValue();
-      double minLat = decodeLatitude(minPackedValue, 0);
-      double minLon = decodeLongitude(minPackedValue, Integer.BYTES);
-
       byte[] maxPackedValue = reader.getMaxPackedValue();
-      double maxLat = decodeLatitude(maxPackedValue, 0);
-      double maxLon = decodeLongitude(maxPackedValue, Integer.BYTES);
       states.add(reader.getIntersectState(visitor));
 
       cellQueue.offer(new Cell(i, 1, reader.getMinPackedValue(), reader.getMaxPackedValue(),
-                               approxBestDistance(minLat, maxLat, minLon, maxLon, pointLat, pointLon)));
+                               approxBestDistance(minPackedValue, maxPackedValue, pointLat, pointLon)));
     }
 
     while (cellQueue.size() > 0) {
@@ -302,7 +294,7 @@ class NearestNeighbor {
     // TODO: can we make this the trueBestDistance?  I.e., minimum distance between the point and ANY point on the box?  we can speed things
     // up if so, but not enrolling any BKD cell whose true best distance is > bottom of the current hit queue
 
-    if (pointLat >= minLat && pointLat <= maxLat && pointLon >= minLon && pointLon <= minLon) {
+    if (pointLat >= minLat && pointLat <= maxLat && pointLon >= minLon && pointLon <= maxLon) {
       // point is inside the cell!
       return 0.0;
     }