use of org.apache.solr.update.processor.BufferingRequestProcessor in project lucene-solr by apache.
the class JsonLoaderTest method testJsonDocFormat.
public void testJsonDocFormat() throws Exception {
String doc = "\n" + "\n" + "{\"bool\": true,\n" + " \"f0\": \"v0\",\n" + " \"f2\": {\n" + " \t \"boost\": 2.3,\n" + " \t \"value\": \"test\"\n" + " \t },\n" + "\"array\": [ \"aaa\", \"bbb\" ],\n" + "\"boosted\": {\n" + " \t \"boost\": 6.7,\n" + " \t \"value\": [ \"aaa\", \"bbb\" ]\n" + " \t }\n" + " }\n" + "\n" + "\n" + " {\"f1\": \"v1\",\n" + " \"f1\": \"v2\",\n" + " \"f2\": null\n" + " }\n";
SolrQueryRequest req = req("srcField", "_src_");
req.getContext().put("path", "/update/json/docs");
SolrQueryResponse rsp = new SolrQueryResponse();
BufferingRequestProcessor p = new BufferingRequestProcessor(null);
JsonLoader loader = new JsonLoader();
loader.load(req, rsp, new ContentStreamBase.StringStream(doc), p);
assertEquals(2, p.addCommands.size());
doc = "\n" + "\n" + "{\"bool\": true,\n" + " \"f0\": \"v0\",\n" + " \"f2\": {\n" + " \t \"boost\": 2.3,\n" + " \t \"value\": \"test\"\n" + " \t },\n" + "\"array\": [ \"aaa\", \"bbb\" ],\n" + "\"boosted\": {\n" + " \t \"boost\": 6.7,\n" + " \t \"value\": [ \"aaa\", \"bbb\" ]\n" + " \t }\n" + " }\n" + "\n" + "\n" + " {\"f1\": \"v1\",\n" + " \"f2\": \"v2\",\n" + " \"f3\": null\n" + " }\n";
req = req("srcField", "_src_");
req.getContext().put("path", "/update/json/docs");
rsp = new SolrQueryResponse();
p = new BufferingRequestProcessor(null);
loader = new JsonLoader();
loader.load(req, rsp, new ContentStreamBase.StringStream(doc), p);
assertEquals(2, p.addCommands.size());
String content = (String) p.addCommands.get(0).solrDoc.getFieldValue("_src_");
assertNotNull(content);
Map obj = (Map) ObjectBuilder.fromJSON(content);
assertEquals(Boolean.TRUE, obj.get("bool"));
assertEquals("v0", obj.get("f0"));
assertNotNull(obj.get("f0"));
assertNotNull(obj.get("array"));
assertNotNull(obj.get("boosted"));
content = (String) p.addCommands.get(1).solrDoc.getFieldValue("_src_");
assertNotNull(content);
obj = (Map) ObjectBuilder.fromJSON(content);
assertEquals("v1", obj.get("f1"));
assertEquals("v2", obj.get("f2"));
assertTrue(obj.containsKey("f3"));
doc = "[{'id':'1'},{'id':'2'}]".replace('\'', '"');
req = req("srcField", "_src_");
req.getContext().put("path", "/update/json/docs");
rsp = new SolrQueryResponse();
p = new BufferingRequestProcessor(null);
loader = new JsonLoader();
loader.load(req, rsp, new ContentStreamBase.StringStream(doc), p);
assertEquals(2, p.addCommands.size());
content = (String) p.addCommands.get(0).solrDoc.getFieldValue("_src_");
assertNotNull(content);
obj = (Map) ObjectBuilder.fromJSON(content);
assertEquals("1", obj.get("id"));
content = (String) p.addCommands.get(1).solrDoc.getFieldValue("_src_");
assertNotNull(content);
obj = (Map) ObjectBuilder.fromJSON(content);
assertEquals("2", obj.get("id"));
String json = "{a:{" + "b:[{c:c1, e:e1},{c:c2, e :e2, d:{p:q}}]," + "x:y" + "}}";
req = req("split", "/|/a/b");
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(1, p.addCommands.size());
assertEquals("y", p.addCommands.get(0).solrDoc.getFieldValue("a.x"));
List<SolrInputDocument> children = p.addCommands.get(0).solrDoc.getChildDocuments();
assertEquals(2, children.size());
SolrInputDocument d = children.get(0);
assertEquals(d.getFieldValue("c"), "c1");
assertEquals(d.getFieldValue("e"), "e1");
d = children.get(1);
assertEquals(d.getFieldValue("c"), "c2");
assertEquals(d.getFieldValue("e"), "e2");
assertEquals(d.getFieldValue("d.p"), "q");
req = req(PARENT_TWO_CHILDREN_PARAMS);
req.getContext().put("path", "/update/json/docs");
rsp = new SolrQueryResponse();
p = new BufferingRequestProcessor(null);
loader = new JsonLoader();
loader.load(req, rsp, new ContentStreamBase.StringStream(PARENT_TWO_CHILDREN_JSON), p);
assertEquals(2, p.addCommands.get(0).solrDoc.getChildDocuments().size());
assertEquals(1, p.addCommands.get(0).solrDoc.getChildDocuments().get(1).getChildDocuments().size());
}
use of org.apache.solr.update.processor.BufferingRequestProcessor in project lucene-solr by apache.
the class JsonLoaderTest method testEmptyChildDocs.
@Test
public void testEmptyChildDocs() throws Exception {
String str = "{\n" + " \"add\": {\n" + " \"doc\": {\n" + " \"id\": \"1\",\n" + " \"_childDocuments_\": []\n" + " }\n" + " }\n" + "}";
SolrQueryRequest req = req("commit", "true");
SolrQueryResponse rsp = new SolrQueryResponse();
BufferingRequestProcessor p = new BufferingRequestProcessor(null);
JsonLoader loader = new JsonLoader();
loader.load(req, rsp, new ContentStreamBase.StringStream(str), p);
assertEquals(1, p.addCommands.size());
AddUpdateCommand add = p.addCommands.get(0);
SolrInputDocument d = add.solrDoc;
SolrInputField f = d.getField("id");
assertEquals("1", f.getValue());
List<SolrInputDocument> cd = d.getChildDocuments();
assertNull(cd);
req.close();
}
use of org.apache.solr.update.processor.BufferingRequestProcessor in project lucene-solr by apache.
the class XmlUpdateRequestHandlerTest method testExternalEntities.
@Test
public void testExternalEntities() throws Exception {
String file = getFile("mailing_lists.pdf").toURI().toASCIIString();
String xml = "<?xml version=\"1.0\"?>" + // check that external entities are not resolved!
"<!DOCTYPE foo [<!ENTITY bar SYSTEM \"" + file + "\">]>" + "<add>" + " &bar;" + " <doc>" + " <field name=\"id\">12345</field>" + " <field name=\"name\">kitten</field>" + " </doc>" + "</add>";
SolrQueryRequest req = req();
SolrQueryResponse rsp = new SolrQueryResponse();
BufferingRequestProcessor p = new BufferingRequestProcessor(null);
XMLLoader loader = new XMLLoader().init(null);
loader.load(req, rsp, new ContentStreamBase.StringStream(xml), p);
AddUpdateCommand add = p.addCommands.get(0);
assertEquals("12345", add.solrDoc.getField("id").getFirstValue());
req.close();
}
use of org.apache.solr.update.processor.BufferingRequestProcessor in project lucene-solr by apache.
the class XmlUpdateRequestHandlerTest method testRequestParams.
@Test
public void testRequestParams() throws Exception {
String xml = "<add>" + " <doc>" + " <field name=\"id\">12345</field>" + " <field name=\"name\">kitten</field>" + " </doc>" + "</add>";
SolrQueryRequest req = req("commitWithin", "100", "overwrite", "false");
SolrQueryResponse rsp = new SolrQueryResponse();
BufferingRequestProcessor p = new BufferingRequestProcessor(null);
XMLLoader loader = new XMLLoader().init(null);
loader.load(req, rsp, new ContentStreamBase.StringStream(xml), p);
AddUpdateCommand add = p.addCommands.get(0);
assertEquals(100, add.commitWithin);
assertEquals(false, add.overwrite);
req.close();
}
use of org.apache.solr.update.processor.BufferingRequestProcessor in project lucene-solr by apache.
the class CSVRequestHandlerTest method testCommitWithin.
@Test
public void testCommitWithin() throws Exception {
String csvString = "id;name\n123;hello";
SolrQueryRequest req = req("separator", ";", "commitWithin", "200");
SolrQueryResponse rsp = new SolrQueryResponse();
BufferingRequestProcessor p = new BufferingRequestProcessor(null);
CSVLoader loader = new CSVLoader();
loader.load(req, rsp, new ContentStreamBase.StringStream.StringStream(csvString), p);
AddUpdateCommand add = p.addCommands.get(0);
assertEquals(200, add.commitWithin);
req.close();
}
Aggregations