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/04/16 17:21:19 UTC
[39/46] lucene-solr:jira/solr-11833: SOLR-11731: one more decimal
place (8) and we get the target/theoretical precision
SOLR-11731: one more decimal place (8) and we get the target/theoretical precision
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/e4eb8a87
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/e4eb8a87
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/e4eb8a87
Branch: refs/heads/jira/solr-11833
Commit: e4eb8a870c342b49c8f0a0864d34617cac1deb0f
Parents: e2e89d1
Author: David Smiley <ds...@apache.org>
Authored: Fri Apr 13 17:05:51 2018 -0400
Committer: David Smiley <ds...@apache.org>
Committed: Fri Apr 13 17:05:51 2018 -0400
----------------------------------------------------------------------
solr/CHANGES.txt | 2 +-
.../apache/solr/schema/LatLonPointSpatialField.java | 15 +++++++++------
.../org/apache/solr/search/TestSolr4Spatial2.java | 16 ++++++++--------
3 files changed, 18 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/e4eb8a87/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 399a2a7..de748be 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -165,7 +165,7 @@ Optimizations
a 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.33cm (Karthik Ramachandran, David Smiley)
+ albeit with maximum precision of 1.04cm (Karthik Ramachandran, David Smiley)
* SOLR-11891: DocStreamer now respects the ReturnFields when populating a SolrDocument, reducing the
number of unneccessary fields a ResponseWriter will see if documentCache is used (wei wang, hossman)
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/e4eb8a87/solr/core/src/java/org/apache/solr/schema/LatLonPointSpatialField.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/schema/LatLonPointSpatialField.java b/solr/core/src/java/org/apache/solr/schema/LatLonPointSpatialField.java
index f612a4a..dd3f586 100644
--- a/solr/core/src/java/org/apache/solr/schema/LatLonPointSpatialField.java
+++ b/solr/core/src/java/org/apache/solr/schema/LatLonPointSpatialField.java
@@ -19,6 +19,7 @@ package org.apache.solr.schema;
import java.io.IOException;
import java.math.BigDecimal;
+import java.math.RoundingMode;
import java.util.Objects;
import org.apache.lucene.document.Field;
@@ -53,7 +54,7 @@ import static java.math.RoundingMode.CEILING;
/**
* A spatial implementation based on Lucene's {@code LatLonPoint} and {@code LatLonDocValuesField}. The
* first is based on Lucene's "Points" API, which is a BKD Index. This field type is strictly limited to
- * coordinates in lat/lon decimal degrees. The accuracy is about a centimeter.
+ * coordinates in lat/lon decimal degrees. The accuracy is about a centimeter (1.042cm).
*/
// TODO once LLP & LLDVF are out of Lucene Sandbox, we should be able to javadoc reference them.
public class LatLonPointSpatialField extends AbstractSpatialFieldType implements SchemaAware {
@@ -81,16 +82,18 @@ public class LatLonPointSpatialField extends AbstractSpatialFieldType implements
* The encoding is governed by {@code LatLonDocValuesField}. The decimal output representation is reflective
* of the available precision.
* @param value Non-null; stored location field data
- * @return Non-null; "lat, lon" with 6 decimal point precision
+ * @return Non-null; "lat, lon"
*/
public static String decodeDocValueToString(long value) {
final double latDouble = GeoEncodingUtils.decodeLatitude((int) (value >> 32));
final double lonDouble = GeoEncodingUtils.decodeLongitude((int) (value & 0xFFFFFFFFL));
- // 7 decimal places maximizes our available precision to just over a centimeter; we have a test for it.
+ // This # decimal places maximizes our available precision to just over a centimeter; 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 occurs when we encode.
- BigDecimal latitudeDecoded = BigDecimal.valueOf(latDouble).setScale(7, CEILING);
- BigDecimal longitudeDecoded = BigDecimal.valueOf(lonDouble).setScale(7, CEILING);
+ // reverses the "floor" that occurred when we encoded.
+ final int DECIMAL_PLACES = 8;
+ 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);
return latitudeDecoded.stripTrailingZeros().toPlainString() + ","
+ longitudeDecoded.stripTrailingZeros().toPlainString();
// return ((float)latDouble) + "," + ((float)lonDouble); crude but not quite as accurate
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/e4eb8a87/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial2.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial2.java b/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial2.java
index 854e9c7..df1c8cd 100644
--- a/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial2.java
+++ b/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial2.java
@@ -145,12 +145,12 @@ public class TestSolr4Spatial2 extends SolrTestCaseJ4 {
String ptOrig = GeoTestUtil.nextLatitude() + "," + GeoTestUtil.nextLongitude();
assertU(adoc("id", "0", fld, ptOrig));
assertU(commit());
- // retrieve it (probably less precision
+ // retrieve it (probably less precision)
String ptDecoded1 = (String) client.query(params("q", "id:0")).getResults().get(0).get(fld);
// now write it back
assertU(adoc("id", "0", fld, ptDecoded1));
assertU(commit());
- // retrieve it and hopefully the same
+ // retrieve it; assert that it's the same as written
String ptDecoded2 = (String) client.query(params("q", "id:0")).getResults().get(0).get(fld);
assertEquals("orig:" + ptOrig, ptDecoded1, ptDecoded2);
@@ -158,13 +158,13 @@ public class TestSolr4Spatial2 extends SolrTestCaseJ4 {
final Point ptOrigObj = SpatialUtils.parsePoint(ptOrig, SpatialContext.GEO);
final Point ptDecodedObj = SpatialUtils.parsePoint(ptDecoded1, SpatialContext.GEO);
double deltaCentimeters = SpatialContext.GEO.calcDistance(ptOrigObj, ptDecodedObj) * DistanceUtils.DEG_TO_KM * 1000.0 * 100.0;
-// //See javadocs of LatLonDocValuesField
-// final Point absErrorPt = SpatialContext.GEO.getShapeFactory().pointXY(8.381903171539307E-8, 4.190951585769653E-8);
-// double deltaCentimetersMax
-// = SpatialContext.GEO.calcDistance(absErrorPt, 0,0) * DistanceUtils.DEG_TO_KM * 1000.0 * 100.0;
-// // equals 1.0420371840922256 which is a bit lower than what we're able to do
+ //See javadocs of LatLonDocValuesField for these constants
+ final Point absErrorPt = SpatialContext.GEO.getShapeFactory().pointXY(8.381903171539307E-8, 4.190951585769653E-8);
+ double deltaCentimetersMax
+ = 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 < 1.33);
+ assertTrue("deltaCm too high: " + deltaCentimeters, deltaCentimeters <= deltaCentimetersMax);
}
@Test