diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 0458262b3cd..559d3b30265 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -15,6 +15,9 @@ Optimizations * LUCENE-7071: Reduce bytes copying in OfflineSorter, giving ~10% speedup on merging 2D LatLonPoint values (Mike McCandless) +* LUCENE-7099: LatLonPoint's newDistanceQuery supports two-phase + iteration. (Robert Muir) + Other * LUCENE-7087: Let MemoryIndex#fromDocument(...) accept 'Iterable' diff --git a/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPoint.java b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPoint.java index e8c2f177849..ebf850c9d5a 100644 --- a/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPoint.java +++ b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPoint.java @@ -96,8 +96,10 @@ public class LatLonPoint extends Field { } private static final int BITS = 32; - private static final double LONGITUDE_SCALE = (0x1L<> 32)); + double docLongitude = LatLonPoint.decodeLongitude((int)(encoded & 0xFFFFFFFF)); + if (GeoDistanceUtils.haversin(latitude, longitude, docLatitude, docLongitude) <= radiusMeters) { + return true; + } + } + return false; + } + } + + @Override + public float matchCost() { + return 20; // TODO: make this fancier + } + }; + return new ConstantScoreScorer(this, score(), iterator); } }; } diff --git a/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonPoint.java b/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonPoint.java index 519478f9952..d180d58f567 100644 --- a/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonPoint.java +++ b/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonPoint.java @@ -159,6 +159,16 @@ public class TestLatLonPoint extends LuceneTestCase { assertEquals(-180.0, LatLonPoint.decodeLongitude(LatLonPoint.encodeLongitude(-180.0)), ENCODING_TOLERANCE); } + public void testEncodeDecodeExtremeValues() throws Exception { + assertEquals(Integer.MIN_VALUE, LatLonPoint.encodeLatitude(-90.0)); + assertEquals(0, LatLonPoint.encodeLatitude(0.0)); + assertEquals(Integer.MAX_VALUE, LatLonPoint.encodeLatitude(90.0)); + + assertEquals(Integer.MIN_VALUE, LatLonPoint.encodeLongitude(-180.0)); + assertEquals(0, LatLonPoint.encodeLatitude(0.0)); + assertEquals(Integer.MAX_VALUE, LatLonPoint.encodeLongitude(180.0)); + } + public void testEncodeDecodeIsStable() throws Exception { int iters = atLeast(1000); for(int iter=0;iter