Search in sources :

Example 11 with BufferingRequestProcessor

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());
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrInputDocument(org.apache.solr.common.SolrInputDocument) BufferingRequestProcessor(org.apache.solr.update.processor.BufferingRequestProcessor) JsonLoader(org.apache.solr.handler.loader.JsonLoader) Map(java.util.Map) ContentStreamBase(org.apache.solr.common.util.ContentStreamBase)

Example 12 with BufferingRequestProcessor

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();
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrInputDocument(org.apache.solr.common.SolrInputDocument) BufferingRequestProcessor(org.apache.solr.update.processor.BufferingRequestProcessor) SolrInputField(org.apache.solr.common.SolrInputField) JsonLoader(org.apache.solr.handler.loader.JsonLoader) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) ContentStreamBase(org.apache.solr.common.util.ContentStreamBase) Test(org.junit.Test)

Example 13 with BufferingRequestProcessor

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();
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) BufferingRequestProcessor(org.apache.solr.update.processor.BufferingRequestProcessor) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) XMLLoader(org.apache.solr.handler.loader.XMLLoader) ContentStreamBase(org.apache.solr.common.util.ContentStreamBase) Test(org.junit.Test)

Example 14 with BufferingRequestProcessor

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();
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) BufferingRequestProcessor(org.apache.solr.update.processor.BufferingRequestProcessor) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) XMLLoader(org.apache.solr.handler.loader.XMLLoader) ContentStreamBase(org.apache.solr.common.util.ContentStreamBase) Test(org.junit.Test)

Example 15 with BufferingRequestProcessor

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();
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) BufferingRequestProcessor(org.apache.solr.update.processor.BufferingRequestProcessor) CSVLoader(org.apache.solr.handler.loader.CSVLoader) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) Test(org.junit.Test)

Aggregations

SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)24 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)24 BufferingRequestProcessor (org.apache.solr.update.processor.BufferingRequestProcessor)24 ContentStreamBase (org.apache.solr.common.util.ContentStreamBase)21 AddUpdateCommand (org.apache.solr.update.AddUpdateCommand)19 SolrInputDocument (org.apache.solr.common.SolrInputDocument)17 JsonLoader (org.apache.solr.handler.loader.JsonLoader)17 Test (org.junit.Test)15 SolrInputField (org.apache.solr.common.SolrInputField)11 XMLLoader (org.apache.solr.handler.loader.XMLLoader)3 Map (java.util.Map)2 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)2 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)2 DeleteUpdateCommand (org.apache.solr.update.DeleteUpdateCommand)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ArrayList (java.util.ArrayList)1 UnaryOperator (java.util.function.UnaryOperator)1 BinaryRequestWriter (org.apache.solr.client.solrj.impl.BinaryRequestWriter)1 JavaBinUpdateRequestCodec (org.apache.solr.client.solrj.request.JavaBinUpdateRequestCodec)1 SolrException (org.apache.solr.common.SolrException)1