SOLR-5777: Fix ordering of field values in JSON updates where field name key is repeated

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1572262 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Chris M. Hostetter 2014-02-26 21:26:14 +00:00
parent e4be54e8b5
commit 087041f8c0
3 changed files with 58 additions and 7 deletions

View File

@ -93,6 +93,9 @@ Bug Fixes
* SOLR-5423: CSV output doesn't include function field
(Arun Kumar, hossman, Steve Rowe)
* SOLR-5777: Fix ordering of field values in JSON updates where
field name key is repeated (hossman)
Optimizations
----------------------
* SOLR-1880: Distributed Search skips GET_FIELDS stage if EXECUTE_QUERY

View File

@ -418,11 +418,11 @@ public class JsonLoader extends ContentStreamLoader {
for (;;) {
SolrInputField sif = parseField();
if (sif == null) return sdoc;
SolrInputField prev = sdoc.put(sif.getName(), sif);
if (prev != null) {
// blech - repeated keys
sif.addValue(prev.getValue(), prev.getBoost());
}
// pulling out hte pieces may seem weird, but it's because
// SolrInputDocument.addField will do the right thing
// if the doc already has another value for this field
// (ie: repeating fieldname keys)
sdoc.addField(sif.getName(), sif.getValue(), sif.getBoost());
}
}
@ -550,4 +550,4 @@ public class JsonLoader extends ContentStreamLoader {
}
}
}
}

View File

@ -209,6 +209,54 @@ public class JsonLoaderTest extends SolrTestCaseJ4 {
req.close();
}
public void testFieldValueOrdering() throws Exception {
final String pre = "{'add':[{'id':'1',";
final String post = "},{'id':'2'}]}";
// list
checkFieldValueOrdering((pre+ "'f':[45,67,89]" +post)
.replace('\'', '"'),
1.0F);
// dup fieldname keys
checkFieldValueOrdering((pre+ "'f':45,'f':67,'f':89" +post)
.replace('\'', '"'),
1.0F);
// extended w/boost
checkFieldValueOrdering((pre+ "'f':{'boost':4.0,'value':[45,67,89]}" +post)
.replace('\'', '"'),
4.0F);
// dup keys extended w/ multiplicitive boost
checkFieldValueOrdering((pre+
"'f':{'boost':2.0,'value':[45,67]}," +
"'f':{'boost':2.0,'value':89}"
+post)
.replace('\'', '"'),
4.0F);
}
private void checkFieldValueOrdering(String rawJson, float fBoost) throws Exception {
SolrQueryRequest req = req();
SolrQueryResponse rsp = new SolrQueryResponse();
BufferingRequestProcessor p = new BufferingRequestProcessor(null);
JsonLoader loader = new JsonLoader();
loader.load(req, rsp, new ContentStreamBase.StringStream(rawJson), p);
assertEquals( 2, p.addCommands.size() );
SolrInputDocument d = p.addCommands.get(0).solrDoc;
assertEquals(2, d.getFieldNames().size());
assertEquals("1", d.getFieldValue("id"));
assertEquals(new Object[] {45L, 67L, 89L} , d.getFieldValues("f").toArray());
assertEquals(0.0F, fBoost, d.getField("f").getBoost());
d = p.addCommands.get(1).solrDoc;
assertEquals(1, d.getFieldNames().size());
assertEquals("2", d.getFieldValue("id"));
req.close();
}
public void testExtendedFieldValues() throws Exception {
String str = "[{'id':'1', 'val_s':{'add':'foo'}}]".replace('\'', '"');
SolrQueryRequest req = req();
@ -500,4 +548,4 @@ public class JsonLoaderTest extends SolrTestCaseJ4 {
}
}
}