SOLR-4036: field aliases in fl should not cause properties of target field to be used

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1408560 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2012-11-13 02:41:08 +00:00
parent 8d047adbb9
commit ddb20fd43d
3 changed files with 34 additions and 11 deletions

View File

@ -179,6 +179,9 @@ Bug Fixes
* SOLR-3989: SolrZkClient constructor dropped exception cause when throwing
a 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
----------------------

View File

@ -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);
}
}

View File

@ -59,6 +59,30 @@ public class TestPseudoReturnFields extends SolrTestCaseJ4 {
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}"
);
}
@Test
public void testAllRealFields() throws Exception {