SOLR-7123: Syntax modified. Multiple paths can be added in the split parameter itself (pipe separated)

This commit is contained in:
Noble Paul 2016-06-07 22:19:09 +05:30 committed by anshum
parent 6ffd1ba978
commit 66cd0edc52
4 changed files with 7 additions and 14 deletions

View File

@ -125,9 +125,8 @@ public class JsonLoader extends ContentStreamLoader {
String path = (String) req.getContext().get(PATH); String path = (String) req.getContext().get(PATH);
if (UpdateRequestHandler.DOC_PATH.equals(path) || "false".equals(req.getParams().get("json.command"))) { if (UpdateRequestHandler.DOC_PATH.equals(path) || "false".equals(req.getParams().get("json.command"))) {
String split = req.getParams().get("split"); String split = req.getParams().get("split");
String childSplit = req.getParams().get("child.split");
String[] f = req.getParams().getParams("f"); String[] f = req.getParams().getParams("f");
handleSplitMode(split, childSplit, f, reader); handleSplitMode(split, f, reader);
return; return;
} }
parser = new JSONParser(reader); parser = new JSONParser(reader);
@ -194,7 +193,7 @@ public class JsonLoader extends ContentStreamLoader {
} }
} }
private void handleSplitMode(String split, String childSplit, String[] fields, final Reader reader) throws IOException { private void handleSplitMode(String split, String[] fields, final Reader reader) throws IOException {
if (split == null) split = "/"; if (split == null) split = "/";
if (fields == null || fields.length == 0) fields = new String[]{"$FQN:/**"}; if (fields == null || fields.length == 0) fields = new String[]{"$FQN:/**"};
final boolean echo = "true".equals(req.getParams().get("echo")); final boolean echo = "true".equals(req.getParams().get("echo"));
@ -209,7 +208,7 @@ public class JsonLoader extends ContentStreamLoader {
} }
JsonRecordReader jsonRecordReader = JsonRecordReader.getInst(split, childSplit, Arrays.asList(fields)); JsonRecordReader jsonRecordReader = JsonRecordReader.getInst(split, Arrays.asList(fields));
jsonRecordReader.streamRecords(parser, new JsonRecordReader.Handler() { jsonRecordReader.streamRecords(parser, new JsonRecordReader.Handler() {
ArrayList docs = null; ArrayList docs = null;

View File

@ -370,7 +370,7 @@ public class JsonLoaderTest extends SolrTestCaseJ4 {
"b:[{c:c1, e:e1},{c:c2, e :e2, d:{p:q}}]," + "b:[{c:c1, e:e1},{c:c2, e :e2, d:{p:q}}]," +
"x:y" + "x:y" +
"}}"; "}}";
req = req("split", "/", "child.split" , "/a/b" ); req = req("split", "/|/a/b" );
req.getContext().put("path","/update/json/docs"); req.getContext().put("path","/update/json/docs");
rsp = new SolrQueryResponse(); rsp = new SolrQueryResponse();
p = new BufferingRequestProcessor(null); p = new BufferingRequestProcessor(null);

View File

@ -34,11 +34,10 @@ public class JsonRecordReader {
private Node rootNode = new Node("/", (Node) null); private Node rootNode = new Node("/", (Node) null);
public static JsonRecordReader getInst(String split, String childSplit, List<String> fieldMappings) { public static JsonRecordReader getInst(String split, List<String> fieldMappings) {
JsonRecordReader jsonRecordReader = new JsonRecordReader(); JsonRecordReader jsonRecordReader = new JsonRecordReader();
jsonRecordReader.addSplit(split); jsonRecordReader.addSplit(split);
if (childSplit != null) jsonRecordReader.addSplit(childSplit);
for (String s : fieldMappings) { for (String s : fieldMappings) {
String path = s; String path = s;
int idx = s.indexOf(':'); int idx = s.indexOf(':');
@ -52,9 +51,6 @@ public class JsonRecordReader {
return jsonRecordReader; return jsonRecordReader;
} }
public static JsonRecordReader getInst(String split, List<String> fieldMappings) {
return getInst(split, null, fieldMappings);
}
private JsonRecordReader() { private JsonRecordReader() {
} }

View File

@ -42,8 +42,6 @@ public class TestJsonRecordReader extends SolrTestCaseJ4 {
" {\"c\":\"C2\",\"d\":\"D2\"}\n" + " {\"c\":\"C2\",\"d\":\"D2\"}\n" +
" ]\n" + " ]\n" +
"}"; "}";
// System.out.println(json);
// All parameters are mapped with field name
JsonRecordReader streamer = JsonRecordReader.getInst("/b", Arrays.asList( JsonRecordReader streamer = JsonRecordReader.getInst("/b", Arrays.asList(
"a_s:/a", "a_s:/a",
"c_s:/b/c", "c_s:/b/c",
@ -208,7 +206,7 @@ public class TestJsonRecordReader extends SolrTestCaseJ4 {
"b:{c:d}," + "b:{c:d}," +
"x:y" + "x:y" +
"}}"; "}}";
JsonRecordReader streamer = JsonRecordReader.getInst("/", "/a/b", Arrays.asList("/a/x", "/a/b/*")); JsonRecordReader streamer = JsonRecordReader.getInst("/|/a/b", Arrays.asList("/a/x", "/a/b/*"));
streamer.streamRecords(new StringReader(json), (record, path) -> { streamer.streamRecords(new StringReader(json), (record, path) -> {
assertEquals(record.get("x"), "y"); assertEquals(record.get("x"), "y");
assertEquals(((Map) record.get(null)).get("c"), "d"); assertEquals(((Map) record.get(null)).get("c"), "d");
@ -227,7 +225,7 @@ public class TestJsonRecordReader extends SolrTestCaseJ4 {
assertEquals(m.get("c"), "c2"); assertEquals(m.get("c"), "c2");
assertEquals(m.get("e"), "e2"); assertEquals(m.get("e"), "e2");
}); });
streamer = JsonRecordReader.getInst("/", "/a/b", Arrays.asList("$FQN:/**")); streamer = JsonRecordReader.getInst("/|/a/b", Arrays.asList("$FQN:/**"));
streamer.streamRecords(new StringReader(json), (record, path) -> { streamer.streamRecords(new StringReader(json), (record, path) -> {
assertEquals(record.get("a.x"), "y"); assertEquals(record.get("a.x"), "y");
List l = (List) record.get(null); List l = (List) record.get(null);