SOLR-7123: echo shows wrong output, and added a test for multi level nesting

This commit is contained in:
Noble Paul 2016-06-09 11:34:06 +05:30
parent be01109744
commit fdf2bbbdb1
2 changed files with 50 additions and 5 deletions

View File

@ -221,10 +221,7 @@ public class JsonLoader extends ContentStreamLoader {
docs = new ArrayList(); docs = new ArrayList();
rsp.add("docs", docs); rsp.add("docs", docs);
} }
if (copy.containsKey(null)) { changeChildDoc(copy);
copy.put(CHILD_DOC_KEY, copy.get(null));
copy.remove(null);
}
docs.add(copy); docs.add(copy);
} else { } else {
AddUpdateCommand cmd = new AddUpdateCommand(req); AddUpdateCommand cmd = new AddUpdateCommand(req);
@ -251,7 +248,7 @@ public class JsonLoader extends ContentStreamLoader {
if (o instanceof Map) result.addChildDocument(buildDoc((Map) o)); if (o instanceof Map) result.addChildDocument(buildDoc((Map) o));
} }
} else if (e.getValue() instanceof Map) { } else if (e.getValue() instanceof Map) {
result.addChildDocument(buildDoc((Map) e)); result.addChildDocument(buildDoc((Map) e.getValue()));
} }
} else { } else {
result.setField(e.getKey(), e.getValue()); result.setField(e.getKey(), e.getValue());
@ -659,4 +656,9 @@ public class JsonLoader extends ContentStreamLoader {
} }
} }
private static Map changeChildDoc(Map m) {
if (m.containsKey(null)) m.put(CHILD_DOC_KEY, changeChildDoc((Map) m.remove(null)));
return m;
}
} }

View File

@ -388,6 +388,49 @@ public class JsonLoaderTest extends SolrTestCaseJ4 {
assertEquals(d.getFieldValue("c"), "c2"); assertEquals(d.getFieldValue("c"), "c2");
assertEquals(d.getFieldValue("e"), "e2"); assertEquals(d.getFieldValue("e"), "e2");
assertEquals(d.getFieldValue("d.p"), "q"); assertEquals(d.getFieldValue("d.p"), "q");
json = "{\n" +
" \"id\": \"1\",\n" +
" \"name\": \"i am the parent\",\n" +
" \"cat\": \"parent\",\n" +
" \"children\": [\n" +
" {\n" +
" \"id\": \"1.1\",\n" +
" \"name\": \"i am the 1st child\",\n" +
" \"cat\": \"child\"\n" +
" },\n" +
" {\n" +
" \"id\": \"1.2\",\n" +
" \"name\": \"i am the 2nd child\",\n" +
" \"cat\": \"child\",\n" +
" \"grandchildren\": [\n" +
" {\n" +
" \"id\": \"1.2.1\",\n" +
" \"name\": \"i am the grandchild\",\n" +
" \"cat\": \"grandchild\"\n" +
" }\n" +
" ]\n" +
" }\n" +
" ]\n" +
"}";
req = req(
"split", "/|/children|/children/grandchildren",
"f","$FQN:/**",
"f", "id:/children/id",
"f", "/name",
"f", "/children/name",
"f", "cat:/children/cat",
"f", "id:/children/grandchildren/id",
"f", "name:/children/grandchildren/name",
"f", "cat:/children/grandchildren/cat");
req.getContext().put("path", "/update/json/docs");
rsp = new SolrQueryResponse();
p = new BufferingRequestProcessor(null);
loader = new JsonLoader();
loader.load(req, rsp, new ContentStreamBase.StringStream(json), p);
assertEquals(2, p.addCommands.get(0).solrDoc.getChildDocuments().size());
assertEquals(1, p.addCommands.get(0).solrDoc.getChildDocuments().get(1).getChildDocuments().size());
} }