Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-13966: LatLonPointSpatialField fix for RealTimeGetComponent used in atomic/partial updates. Closes #1035

Thomas Wöckingere250f3e82cb1
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index c56120f44ca..4aa670a82a1 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -218,6 +218,9 @@ Bug Fixes
* SOLR-13977: solr create -c not working under Windows 10 (janhoy)
+* SOLR-13966: LatLonPointSpatialField wasn't working correctly with atomic/partial updates or RTG.
+ (Thomas Wöckinger via David Smiley)
+
Other Changes
---------------------
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 48206f5fca5..386502740f9 100644
--- a/solr/core/src/java/org/apache/solr/schema/LatLonPointSpatialField.java
+++ b/solr/core/src/java/org/apache/solr/schema/LatLonPointSpatialField.java
@@ -27,6 +27,7 @@ import org.apache.lucene.document.LatLonDocValuesField;
import org.apache.lucene.document.LatLonPoint;
import org.apache.lucene.geo.GeoEncodingUtils;
import org.apache.lucene.index.DocValues;
+import org.apache.lucene.index.IndexableField;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.queries.function.ValueSource;
import org.apache.lucene.search.DoubleValues;
@@ -76,7 +77,15 @@ public class LatLonPointSpatialField extends AbstractSpatialFieldType implements
SchemaField schemaField = schema.getField(fieldName); // TODO change AbstractSpatialFieldType so we get schemaField?
return new LatLonPointSpatialStrategy(ctx, fieldName, schemaField.indexed(), schemaField.hasDocValues());
}
-
+
+ @Override
+ public String toExternal(IndexableField f) {
+ if (f.numericValue() != null) {
+ return decodeDocValueToString(f.numericValue().longValue());
+ }
+ return super.toExternal(f);
+ }
+
/**
* Decodes the docValues number into latitude and longitude components, formatting as "lat,lon".
* The encoding is governed by {@code LatLonDocValuesField}. The decimal output representation is reflective
diff --git a/solr/core/src/test-files/solr/collection1/conf/schema-nest.xml b/solr/core/src/test-files/solr/collection1/conf/schema-nest.xml
index 93300579586..f7cab607ede 100644
--- a/solr/core/src/test-files/solr/collection1/conf/schema-nest.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/schema-nest.xml
@@ -54,6 +54,10 @@
<field name="signatureField" type="string" indexed="true" stored="false"/>
<dynamicField name="*_sS" type="string" indexed="true" stored="true" multiValued="true"/>
+ <!-- Fields required for LatLonDocValuesField test -->
+ <fieldType name="latlon" class="solr.LatLonPointSpatialField" docValues="true"/>
+ <field name="latlon" type="latlon" indexed="true" stored="false"/>
+
<uniqueKey>id</uniqueKey>
</schema>
diff --git a/solr/core/src/test/org/apache/solr/update/processor/NestedAtomicUpdateTest.java b/solr/core/src/test/org/apache/solr/update/processor/NestedAtomicUpdateTest.java
index 62f412aaa8c..e016d2ccf46 100644
--- a/solr/core/src/test/org/apache/solr/update/processor/NestedAtomicUpdateTest.java
+++ b/solr/core/src/test/org/apache/solr/update/processor/NestedAtomicUpdateTest.java
@@ -653,7 +653,9 @@ public class NestedAtomicUpdateTest extends SolrTestCaseJ4 {
}
private void testBlockAtomicSetToNullOrEmpty(boolean empty) throws Exception {
- SolrInputDocument doc = sdoc("id", "1",
+ // latlon field is included to ensure reading from LatLonDocValuesField is working due to atomic update.
+ // See SOLR-13966 for further details.
+ SolrInputDocument doc = sdoc("id", "1", "latlon", "0,0",
"cat_ss", new String[] {"aaa", "ccc"},
"child1", sdocs(sdoc("id", "2", "cat_ss", "child"), sdoc("id", "3", "cat_ss", "child")));
assertU(adoc(doc));
@@ -679,32 +681,35 @@ public class NestedAtomicUpdateTest extends SolrTestCaseJ4 {
assertJQ(req("q", "id:1"), "/response/numFound==1");
- assertJQ(req("qt", "/get", "id", "1", "fl", "id, cat_ss, child1, [child]"), "=={\"doc\":{'id':\"1\"" +
- ", cat_ss:[\"aaa\",\"ccc\"], child1:[{\"id\":\"2\",\"cat_ss\":[\"child\"]}, {\"id\":\"3\",\"cat_ss\":[\"child\"]}]}}");
+ assertJQ(req("qt", "/get", "id", "1", "fl", "id, latlon, cat_ss, child1, [child]"),
+ "=={\"doc\":{'id':\"1\", \"latlon\":\"0,0\"" +
+ ", cat_ss:[\"aaa\",\"ccc\"], child1:[{\"id\":\"2\",\"cat_ss\":[\"child\"]}, {\"id\":\"3\",\"cat_ss\":[\"child\"]}]}}");
assertU(commit());
- assertJQ(req("qt", "/get", "id", "1", "fl", "id, cat_ss, child1, [child]"), "=={\"doc\":{'id':\"1\"" +
- ", cat_ss:[\"aaa\",\"ccc\"], child1:[{\"id\":\"2\",\"cat_ss\":[\"child\"]}, {\"id\":\"3\",\"cat_ss\":[\"child\"]}]}}");
+ assertJQ(req("qt", "/get", "id", "1", "fl", "id, latlon, cat_ss, child1, [child]"),
+ "=={\"doc\":{'id':\"1\", \"latlon\":\"0,0\"" +
+ ", cat_ss:[\"aaa\",\"ccc\"], child1:[{\"id\":\"2\",\"cat_ss\":[\"child\"]}, {\"id\":\"3\",\"cat_ss\":[\"child\"]}]}}");
- doc = sdoc("id", "1", "child1", Collections.singletonMap("set", empty ? new ArrayList<>() : null));
+ doc = sdoc("id", "1", "child1", Collections.singletonMap("set", null));
addAndGetVersion(doc, params("wt", "json"));
- assertJQ(req("qt", "/get", "id", "1", "fl", "id, cat_ss, child1, [child]"),
- "=={\"doc\":{'id':\"1\", cat_ss:[\"aaa\",\"ccc\"]}}");
+ assertJQ(req("qt", "/get", "id", "1", "fl", "id, latlon, cat_ss, child1, [child]"),
+ "=={\"doc\":{'id':\"1\", \"latlon\":\"0,0\", cat_ss:[\"aaa\",\"ccc\"]}}");
assertU(commit());
// a cut-n-paste of the first big query, but this time it will be retrieved from the index rather than the
// transaction log
// this requires ChildDocTransformer to get the whole block, since the document is retrieved using an index lookup
- assertJQ(req("qt", "/get", "id", "1", "fl", "id, cat_ss, child1, [child]"),
- "=={'doc':{'id':'1', cat_ss:[\"aaa\",\"ccc\"]}}");
+ assertJQ(req("qt", "/get", "id", "1", "fl", "id, latlon, cat_ss, child1, [child]"),
+ "=={\"doc\":{'id':\"1\", \"latlon\":\"0,0\", cat_ss:[\"aaa\",\"ccc\"]}}");
// ensure the whole block has been committed correctly to the index.
assertJQ(req("q", "id:1", "fl", "*, [child]"),
"/response/numFound==1",
"/response/docs/[0]/id=='1'",
+ "/response/docs/[0]/latlon=='0,0'",
"/response/docs/[0]/cat_ss/[0]==\"aaa\"",
"/response/docs/[0]/cat_ss/[1]==\"ccc\"");
}