Apache Lucene open-source search software
LUCENE-8120: Fix LatLonBoundingBox's toString() method
Martijn van Groningen35e6923677a1
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 570da98a654..36c13241ff5 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -35,7 +35,7 @@ API Changes* LUCENE-8116: SimScorer now only takes a frequency and a norm as per-documentscoring factors. (Adrien Grand)-* LUCENE-8113: TermContext has been renamed to TermStates, and can now be+* LUCENE-8113: TermContext has been renamed to TermStates, and can now beconstructed lazily if term statistics are not required (Alan Woodward)Changes in Runtime Behavior@@ -137,6 +137,8 @@ Bug Fixesproblem (LUCENE-2287, LUCENE-5455, LUCENE-6796). Some public but internal parts ofthe UH were refactored. (David Smiley, Steve Davids)+* LUCENE-8120: Fix LatLonBoundingBox's toString() method (Martijn van Groningen, Adrien Grand)+Other* LUCENE-8111: IndexOrDocValuesQuery Javadoc references outdated method name.diff --git a/lucene/sandbox/src/java/org/apache/lucene/document/LatLonBoundingBox.java b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonBoundingBox.javaindex c6d8b5551cf..3a2264ccd2e 100644--- a/lucene/sandbox/src/java/org/apache/lucene/document/LatLonBoundingBox.java+++ b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonBoundingBox.java@@ -203,29 +203,30 @@ public class LatLonBoundingBox extends Field {sb.append(" <");sb.append(name);sb.append(':');+ sb.append('[');byte[] b = ((BytesRef)fieldsData).bytes;- toString(b, 0);+ sb.append(toString(b, 0));+ sb.append(',');+ sb.append(toString(b, 1));+ sb.append(']');sb.append('>');-return sb.toString();}private static String toString(byte[] ranges, int dimension) {- double min, max;- int minOfs = 0;- int maxOfs = ranges.length/2;+ double lat, lon;switch (dimension) {case 0:- min = decodeLatitude(ranges, minOfs);- max = decodeLatitude(ranges, maxOfs);+ lat = decodeLatitude(ranges, 0);+ lon = decodeLongitude(ranges, 4);break;case 1:- min = decodeLongitude(ranges, minOfs);- max = decodeLongitude(ranges, maxOfs);+ lat = decodeLatitude(ranges, 8);+ lon = decodeLongitude(ranges, 12);break;default:throw new IllegalArgumentException("invalid dimension [" + dimension + "] in toString");}- return "[" + min + " : " + max + "]";+ return lat + "," + lon;}}diff --git a/lucene/sandbox/src/test/org/apache/lucene/search/TestLatLonBoundingBoxQueries.java b/lucene/sandbox/src/test/org/apache/lucene/search/TestLatLonBoundingBoxQueries.javaindex 39d32a17b65..7506fb89e8a 100644--- a/lucene/sandbox/src/test/org/apache/lucene/search/TestLatLonBoundingBoxQueries.java+++ b/lucene/sandbox/src/test/org/apache/lucene/search/TestLatLonBoundingBoxQueries.java@@ -97,6 +97,12 @@ public class TestLatLonBoundingBoxQueries extends BaseRangeFieldQueryTestCase {dir.close();}+ public void testToString() {+ LatLonBoundingBox field = new LatLonBoundingBox(FIELD_NAME, -20d, -180d, 20d, -100d);+ String expected = "LatLonBoundingBox <geoBoundingBoxField:[-20.000000023283064,-180.0,19.99999998137355,-100.0000000745058]>";+ assertEquals(expected, field.toString());+ }+@Overrideprotected int dimension() {return 2;