Apache Lucene open-source search software
SOLR-4036: field aliases in fl should not cause properties of target field to be used
Yonik Seeleyddb20fd43d8e
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 54c2533ee12..26a6cdd11df 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -179,6 +179,9 @@ Bug Fixes* SOLR-3989: SolrZkClient constructor dropped exception cause when throwinga new RuntimeException. (Colin Bartolome, yonik)+* SOLR-4036: field aliases in fl should not cause properties of target field+ to be used. (Martin Koch, yonik)+Other Changes----------------------diff --git a/solr/core/src/java/org/apache/solr/response/JSONResponseWriter.java b/solr/core/src/java/org/apache/solr/response/JSONResponseWriter.javaindex ee9ebdbeb52..e37f5a94fdc 100644--- a/solr/core/src/java/org/apache/solr/response/JSONResponseWriter.java+++ b/solr/core/src/java/org/apache/solr/response/JSONResponseWriter.java@@ -23,6 +23,7 @@ import java.util.ArrayList;import java.util.Collection;import java.util.HashMap;import java.util.Iterator;+import java.util.List;import java.util.Map;import java.util.Set;@@ -342,18 +343,13 @@ class JSONWriter extends TextResponseWriter {writeKey(fname, true);Object val = doc.getFieldValue(fname);- if (val instanceof Collection) {- writeVal(fname, val);+ // SolrDocument will now have multiValued fields represented as a Collection,+ // even if only a single value is returned for this document.+ if (val instanceof List) {+ // shortcut this common case instead of going through writeVal again+ writeArray(name,((Iterable)val).iterator());} else {- // if multivalued field, write single value as an array- SchemaField sf = schema.getFieldOrNull(fname);- if (sf != null && sf.multiValued()) {- writeArrayOpener(-1); // no trivial way to determine array size- writeVal(fname, val);- writeArrayCloser();- } else {- writeVal(fname, val);- }+ writeVal(fname, val);}}diff --git a/solr/core/src/test/org/apache/solr/search/TestPseudoReturnFields.java b/solr/core/src/test/org/apache/solr/search/TestPseudoReturnFields.javaindex 05a8de13755..e457ce2e7e8 100644--- a/solr/core/src/test/org/apache/solr/search/TestPseudoReturnFields.java+++ b/solr/core/src/test/org/apache/solr/search/TestPseudoReturnFields.java@@ -58,6 +58,30 @@ public class TestPseudoReturnFields extends SolrTestCaseJ4 {assertU(adoc("id", "46", "val_i", "3", "ssto", "X", "subject", "ggg"));assertU(commit());}++ @Test+ public void testMultiValued() throws Exception {+ // the response writers used to consult isMultiValued on the field+ // but this doesn't work when you alias a single valued field to+ // a multi valued field (the field value is copied first, then+ // if the type lookup is done again later, we get the wrong thing). SOLR-4036++ assertJQ(req("q","id:42", "fl","val_ss:val_i, val2_ss:10")+ ,"/response/docs==[{'val2_ss':10,'val_ss':1}]"+ );++ assertJQ(req("qt","/get", "id","42", "fl","val_ss:val_i, val2_ss:10")+ ,"/doc=={'val2_ss':10,'val_ss':1}"+ );++ // also check real-time-get from transaction log+ assertU(adoc("id", "42", "val_i", "1", "ssto", "X", "subject", "aaa"));++ assertJQ(req("qt","/get", "id","42", "fl","val_ss:val_i, val2_ss:10")+ ,"/doc=={'val2_ss':10,'val_ss':1}"+ );++ }@Testpublic void testAllRealFields() throws Exception {