use of org.apache.solr.request.SolrQueryRequest in project lucene-solr by apache.
the class JsonLoaderTest method testDecimalValuesInAdd.
@Test
public void testDecimalValuesInAdd() throws Exception {
String str = "{'add':[{'id':'1','d1':256.78,'d2':-5123456789.0,'d3':0.0,'d3':1.0,'d4':1.7E-10}]}".replace('\'', '"');
SolrQueryRequest req = req();
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("d1");
assertEquals(256.78, f.getValue());
f = d.getField("d2");
assertEquals(-5123456789.0, f.getValue());
f = d.getField("d3");
assertEquals(2, ((List) f.getValue()).size());
assertTrue(((List) f.getValue()).contains(0.0));
assertTrue(((List) f.getValue()).contains(1.0));
f = d.getField("d4");
assertEquals(1.7E-10, f.getValue());
req.close();
}
use of org.apache.solr.request.SolrQueryRequest in project lucene-solr by apache.
the class JsonLoaderTest method testBooleanValuesInAdd.
@Test
public void testBooleanValuesInAdd() throws Exception {
String str = "{'add':[{'id':'1','b1':true,'b2':false,'b3':[false,true]}]}".replace('\'', '"');
SolrQueryRequest req = req();
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("b1");
assertEquals(Boolean.TRUE, f.getValue());
f = d.getField("b2");
assertEquals(Boolean.FALSE, f.getValue());
f = d.getField("b3");
assertEquals(2, ((List) f.getValue()).size());
assertEquals(Boolean.FALSE, ((List) f.getValue()).get(0));
assertEquals(Boolean.TRUE, ((List) f.getValue()).get(1));
req.close();
}
use of org.apache.solr.request.SolrQueryRequest in project lucene-solr by apache.
the class JsonLoaderTest method checkTwoChildDocs.
private void checkTwoChildDocs(String rawJsonStr) throws Exception {
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(rawJsonStr), 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());
SolrInputDocument cd = d.getChildDocuments().get(0);
SolrInputField cf = cd.getField("id");
assertEquals("2", cf.getValue());
cd = d.getChildDocuments().get(1);
cf = cd.getField("id");
assertEquals("3", cf.getValue());
cf = cd.getField("foo_i");
assertEquals(2, cf.getValueCount());
assertEquals(new Object[] { 666L, 777L }, cf.getValues().toArray());
req.close();
}
use of org.apache.solr.request.SolrQueryRequest in project lucene-solr by apache.
the class JsonLoaderTest method testSimpleFormatInAdd.
public void testSimpleFormatInAdd() throws Exception {
String str = "{'add':[{'id':'1'},{'id':'2'}]}".replace('\'', '"');
SolrQueryRequest req = req();
SolrQueryResponse rsp = new SolrQueryResponse();
BufferingRequestProcessor p = new BufferingRequestProcessor(null);
JsonLoader loader = new JsonLoader();
loader.load(req, rsp, new ContentStreamBase.StringStream(str), p);
assertEquals(2, p.addCommands.size());
AddUpdateCommand add = p.addCommands.get(0);
SolrInputDocument d = add.solrDoc;
SolrInputField f = d.getField("id");
assertEquals("1", f.getValue());
assertEquals(add.commitWithin, -1);
assertEquals(add.overwrite, true);
add = p.addCommands.get(1);
d = add.solrDoc;
f = d.getField("id");
assertEquals("2", f.getValue());
assertEquals(add.commitWithin, -1);
assertEquals(add.overwrite, true);
req.close();
}
use of org.apache.solr.request.SolrQueryRequest 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());
}
Aggregations