Apache Lucene open-source search software
SOLR-3743: real-time get should not return copyField targets
Yonik Seeley97689f52f233
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 3046fc4a642..7d7160d2f20 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -78,6 +78,11 @@ Bug Fixeswhen requesting multiple stats.facet fields.(Roman Kliewer via hossman)+* SOLR-3743: Fixed issues with atomic updates and optimistic concurrency in+ conjunction with stored copyField targets by making real-time get never+ return copyField targets. (yonik)++Other Changes----------------------diff --git a/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java b/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.javaindex 65d17eca022..a09203b2607 100644--- a/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java+++ b/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java@@ -255,6 +255,7 @@ public class RealTimeGetComponent extends SearchComponentSchemaField sf = schema.getFieldOrNull(f.name());Object val = null;if (sf != null) {+ if (!sf.stored() || schema.isCopyFieldTarget(sf)) continue;val = sf.getType().toObject(f); // object or external string?} else {val = f.stringValue();@@ -277,6 +278,10 @@ public class RealTimeGetComponent extends SearchComponentObject existing = out.get(f.name());if (existing == null) {SchemaField sf = schema.getFieldOrNull(f.name());++ // don't return copyField targets+ if (sf != null && schema.isCopyFieldTarget(sf)) continue;+if (sf != null && sf.multiValued()) {List<Object> vals = new ArrayList<Object>();vals.add( f );@@ -301,7 +306,7 @@ public class RealTimeGetComponent extends SearchComponent// copy the stored fields onlyDocument out = new Document();for (IndexableField f : doc.getFields()) {- if (f.fieldType().stored()) {+ if (f.fieldType().stored() ) {out.add(f);}}diff --git a/solr/core/src/test-files/solr/collection1/conf/schema15.xml b/solr/core/src/test-files/solr/collection1/conf/schema15.xmlindex 48c2c9ec9a2..62e26fdb3f5 100755--- a/solr/core/src/test-files/solr/collection1/conf/schema15.xml+++ b/solr/core/src/test-files/solr/collection1/conf/schema15.xml@@ -425,7 +425,7 @@<field name="signatureField" type="string" indexed="true" stored="false"/><field name="uuid" type="uuid" stored="true" /><field name="name" type="nametext" indexed="true" stored="true"/>- <field name="text" type="text" indexed="true" stored="false"/>+ <field name="text" type="text" indexed="true" stored="false" multiValued="true" /><field name="subject" type="text" indexed="true" stored="true"/><field name="title" type="nametext" indexed="true" stored="true"/><field name="weight" type="float" indexed="true" stored="true"/>@@ -522,6 +522,9 @@<!-- for versioning --><field name="_version_" type="long" indexed="true" stored="true"/>++ <field name="copyfield_source" type="string" indexed="true" stored="true" multiValued="true"/>+<dynamicField name="*_coordinate" type="tdouble" indexed="true" stored="false"/>@@ -587,5 +590,8 @@<copyField source="title" dest="text"/><copyField source="subject" dest="text"/>++ <copyField source="copyfield_source" dest="text"/>+ <copyField source="copyfield_source" dest="copyfield_dest_ss"/> <!-- copyField into another stored copyField - not best practice --></schema>diff --git a/solr/core/src/test/org/apache/solr/update/TestUpdate.java b/solr/core/src/test/org/apache/solr/update/TestUpdate.javaindex 1369d3f28f2..2f035ad087f 100644--- a/solr/core/src/test/org/apache/solr/update/TestUpdate.java+++ b/solr/core/src/test/org/apache/solr/update/TestUpdate.java@@ -68,7 +68,7 @@ public class TestUpdate extends SolrTestCaseJ4 {doUpdateTest(new Callable() {@Overridepublic Object call() throws Exception {- commit("softCommit","false");+ assertU(commit("softCommit","false"));return null;}});@@ -82,15 +82,15 @@ public class TestUpdate extends SolrTestCaseJ4 {long version;- version = addAndGetVersion(sdoc("id","1", "val_i",5), null);+ version = addAndGetVersion(sdoc("id","1", "val_i",5, "copyfield_source","a"), null);afterUpdate.call();- version = addAndGetVersion(sdoc("id","1", "val_is",map("add",10)), null);+ version = addAndGetVersion(sdoc("id","1", "val_is",map("add",10), "copyfield_source",map("add","b")), null);afterUpdate.call();version = addAndGetVersion(sdoc("id","1", "val_is",map("add",5)), null);afterUpdate.call();- assertJQ(req("qt","/get", "id","1", "fl","id,*_i,*_is")- ,"=={'doc':{'id':'1', 'val_i':5, 'val_is':[10,5]}}"+ assertJQ(req("qt","/get", "id","1", "fl","id,*_i,*_is,copyfield_*")+ ,"=={'doc':{'id':'1', 'val_i':5, 'val_is':[10,5], 'copyfield_source':['a','b']}}" // real-time get should not return stored copyfield targets);version = addAndGetVersion(sdoc("id","1", "val_is",map("add",-1), "val_i",map("set",100)), null);@@ -101,6 +101,14 @@ public class TestUpdate extends SolrTestCaseJ4 {);+ // Do a search to get all stored fields back and make sure that the stored copyfield target only+ // has one copy of the source. This may not be supported forever!+ assertU(commit("softCommit","true"));+ assertJQ(req("q","*:*", "fl","id,*_i,*_is,copyfield_*")+ ,"/response/docs/[0]=={'id':'1', 'val_i':100, 'val_is':[10,5,-1], 'copyfield_source':['a','b'], 'copyfield_dest_ss':['a','b']}"+ );++long version2;try {// try bad version added as a field in the doc