You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ab...@apache.org on 2018/01/23 13:27:38 UTC

[06/51] lucene-solr:jira/solr-11714: LUCENE-8120: Fix LatLonBoundingBox's toString() method

LUCENE-8120: Fix LatLonBoundingBox's toString() method


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

Branch: refs/heads/jira/solr-11714
Commit: 35e6923677a112bc6e752954118f6d4b4a8aff40
Parents: fd7aea5
Author: Martijn van Groningen <ma...@gmail.com>
Authored: Thu Jan 11 15:08:05 2018 +0100
Committer: Martijn van Groningen <mv...@apache.org>
Committed: Thu Jan 11 15:09:13 2018 +0100

----------------------------------------------------------------------
 lucene/CHANGES.txt                              |  4 +++-
 .../lucene/document/LatLonBoundingBox.java      | 21 ++++++++++----------
 .../search/TestLatLonBoundingBoxQueries.java    |  6 ++++++
 3 files changed, 20 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/35e69236/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 570da98..36c1324 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-document
   scoring 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 be
   constructed lazily if term statistics are not required (Alan Woodward)
 
 Changes in Runtime Behavior
@@ -137,6 +137,8 @@ Bug Fixes
   problem (LUCENE-2287, LUCENE-5455, LUCENE-6796).  Some public but internal parts of
   the 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.

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/35e69236/lucene/sandbox/src/java/org/apache/lucene/document/LatLonBoundingBox.java
----------------------------------------------------------------------
diff --git a/lucene/sandbox/src/java/org/apache/lucene/document/LatLonBoundingBox.java b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonBoundingBox.java
index c6d8b55..3a2264c 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;
   }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/35e69236/lucene/sandbox/src/test/org/apache/lucene/search/TestLatLonBoundingBoxQueries.java
----------------------------------------------------------------------
diff --git a/lucene/sandbox/src/test/org/apache/lucene/search/TestLatLonBoundingBoxQueries.java b/lucene/sandbox/src/test/org/apache/lucene/search/TestLatLonBoundingBoxQueries.java
index 39d32a1..7506fb8 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());
+  }
+
   @Override
   protected int dimension() {
     return 2;