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);
if (UpdateRequestHandler.DOC_PATH.equals(path) || "false".equals(req.getParams().get("json.command"))) {
String split = req.getParams().get("split");
String childSplit = req.getParams().get("child.split");
String[] f = req.getParams().getParams("f");
handleSplitMode(split, childSplit, f, reader);
handleSplitMode(split, f, reader);
return;
}
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 (fields == null || fields.length == 0) fields = new String[]{"$FQN:/**"};
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() {
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}}]," +
"x:y" +
"}}";
req = req("split", "/", "child.split" , "/a/b" );
req = req("split", "/|/a/b" );
req.getContext().put("path","/update/json/docs");
rsp = new SolrQueryResponse();
p = new BufferingRequestProcessor(null);

View File

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

View File

@ -42,8 +42,6 @@ public class TestJsonRecordReader extends SolrTestCaseJ4 {
" {\"c\":\"C2\",\"d\":\"D2\"}\n" +
" ]\n" +
"}";
// System.out.println(json);
// All parameters are mapped with field name
JsonRecordReader streamer = JsonRecordReader.getInst("/b", Arrays.asList(
"a_s:/a",
"c_s:/b/c",
@ -208,7 +206,7 @@ public class TestJsonRecordReader extends SolrTestCaseJ4 {
"b:{c:d}," +
"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) -> {
assertEquals(record.get("x"), "y");
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("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) -> {
assertEquals(record.get("a.x"), "y");
List l = (List) record.get(null);