Apache Lucene open-source search software
SOLR-11731: revert to 7 decimal places so we can maintain the round-trip property. Add test that we round-trip random numbers at 7 decimal places. Would fail at 8.
David Smileydad2d1076db6
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex b39fd6f91ab..08c246fc978 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -168,7 +168,7 @@ Optimizationsa few segments diverge. (Ishan Chattopadhyaya, Shaun Sabo, John Gallagher)* SOLR-11731: LatLonPointSpatialField can now decode points from docValues when stored=false docValues=true,- albeit with maximum precision of 1.04cm (Karthik Ramachandran, David Smiley)+ albeit with maximum precision of 1.37cm (Karthik Ramachandran, David Smiley)* SOLR-11891: DocStreamer now respects the ReturnFields when populating a SolrDocument, reducing thenumber of unneccessary fields a ResponseWriter will see if documentCache is used (wei wang, hossman)diff --git a/solr/core/src/java/org/apache/solr/schema/LatLonPointSpatialField.java b/solr/core/src/java/org/apache/solr/schema/LatLonPointSpatialField.javaindex dd3f586b3b4..dfdd0744c63 100644--- a/solr/core/src/java/org/apache/solr/schema/LatLonPointSpatialField.java+++ b/solr/core/src/java/org/apache/solr/schema/LatLonPointSpatialField.java@@ -87,10 +87,10 @@ public class LatLonPointSpatialField extends AbstractSpatialFieldType implementspublic static String decodeDocValueToString(long value) {final double latDouble = GeoEncodingUtils.decodeLatitude((int) (value >> 32));final double lonDouble = GeoEncodingUtils.decodeLongitude((int) (value & 0xFFFFFFFFL));- // This # decimal places maximizes our available precision to just over a centimeter; we have a test for it.+ // This # decimal places gets us close to our available precision to 1.37cm; we have a test for it.// CEILING round-trips (decode then re-encode then decode to get identical results). Others did not. It also// reverses the "floor" that occurred when we encoded.- final int DECIMAL_PLACES = 8;+ final int DECIMAL_PLACES = 7;final RoundingMode ROUND_MODE = CEILING;BigDecimal latitudeDecoded = BigDecimal.valueOf(latDouble).setScale(DECIMAL_PLACES, ROUND_MODE);BigDecimal longitudeDecoded = BigDecimal.valueOf(lonDouble).setScale(DECIMAL_PLACES, ROUND_MODE);diff --git a/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial2.java b/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial2.javaindex df1c8cde694..e5dc6918c73 100644--- a/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial2.java+++ b/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial2.java@@ -16,6 +16,7 @@*/package org.apache.solr.search;+import java.math.BigDecimal;import java.util.ArrayList;import java.util.Arrays;import java.util.Collections;@@ -56,6 +57,7 @@ public class TestSolr4Spatial2 extends SolrTestCaseJ4 {public void setUp() throws Exception {super.setUp();clearIndex();+ RetrievalCombo.idCounter = 0;}@Test@@ -164,18 +166,25 @@ public class TestSolr4Spatial2 extends SolrTestCaseJ4 {= SpatialContext.GEO.calcDistance(absErrorPt, 0,0) * DistanceUtils.DEG_TO_KM * 1000.0 * 100.0;assertEquals(1.0420371840922256, deltaCentimetersMax, 0.0);// just so that we see it in black & white in the test- assertTrue("deltaCm too high: " + deltaCentimeters, deltaCentimeters <= deltaCentimetersMax);+ //max found by trial & error. If we used 8 decimal places then we could get down to 1.04cm accuracy but then we+ // lose the ability to round-trip -- 40 would become 39.99999997 (ugh).+ assertTrue("deltaCm too high: " + deltaCentimeters, deltaCentimeters <= 1.37);}@Testpublic void testLatLonRetrieval() throws Exception {- final String ptHighPrecision = "40.2996543270,-74.0824956673";+ final String ptHighPrecision = "40.2996543270,-74.0824956673";final String ptLossOfPrecision = "40.2996544,-74.0824957"; // rounded version of the one above, losing precision// "_1" is single, "_N" is multiValued// "_dv" is docValues (otherwise not), "_dvasst" is useDocValuesAsStored (otherwise not)// "_st" is stored" (otherwise not)+ // a random point using the number of decimal places we support for round-tripping.+ String randPointStr =+ new BigDecimal(GeoTestUtil.nextLatitude()).setScale(7, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString() ++ "," + new BigDecimal(GeoTestUtil.nextLongitude()).setScale(7, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString();+List<RetrievalCombo> combos = Arrays.asList(new RetrievalCombo("llp_1_dv_st", ptHighPrecision),new RetrievalCombo("llp_N_dv_st", Arrays.asList("-40,40", "-45,45")),@@ -184,7 +193,7 @@ public class TestSolr4Spatial2 extends SolrTestCaseJ4 {new RetrievalCombo("llp_1_dv_dvasst", ptHighPrecision, ptLossOfPrecision),// this one comes back in a different order since it gets sorted low to highnew RetrievalCombo("llp_N_dv_dvasst", Arrays.asList("-40,40", "-45,45"), Arrays.asList("-45,45", "-40,40")),- new RetrievalCombo("llp_N_dv_dvasst", Arrays.asList("-40,40")), // multiValued but 1 value+ new RetrievalCombo("llp_N_dv_dvasst", Arrays.asList(randPointStr)), // multiValued but 1 value// edge cases. (note we sorted it as Lucene will internally)new RetrievalCombo("llp_N_dv_dvasst", Arrays.asList("-90,180", "-90,-180",