use of org.apache.solr.client.solrj.request.RequestWriter in project lucene-solr by apache.
the class AddBlockUpdateTest method testXML.
//This is the same as testSolrJXML above but uses the XMLLoader
// to illustrate the structure of the XML documents
@Test
public void testXML() throws IOException, XMLStreamException {
UpdateRequest req = new UpdateRequest();
List<SolrInputDocument> docs = new ArrayList<>();
String xml_doc1 = "<doc >" + " <field name=\"id\">1</field>" + " <field name=\"parent_s\">X</field>" + "<doc> " + " <field name=\"id\" >2</field>" + " <field name=\"child_s\">y</field>" + "</doc>" + "<doc> " + " <field name=\"id\" >3</field>" + " <field name=\"child_s\">z</field>" + "</doc>" + "</doc>";
String xml_doc2 = "<doc >" + " <field name=\"id\">4</field>" + " <field name=\"parent_s\">A</field>" + "<doc> " + " <field name=\"id\" >5</field>" + " <field name=\"child_s\">b</field>" + "</doc>" + "<doc> " + " <field name=\"id\" >6</field>" + " <field name=\"child_s\">c</field>" + "</doc>" + "</doc>";
XMLStreamReader parser = inputFactory.createXMLStreamReader(new StringReader(xml_doc1));
// read the START document...
parser.next();
//null for the processor is all right here
XMLLoader loader = new XMLLoader();
SolrInputDocument document1 = loader.readDoc(parser);
XMLStreamReader parser2 = inputFactory.createXMLStreamReader(new StringReader(xml_doc2));
// read the START document...
parser2.next();
//null for the processor is all right here
//XMLLoader loader = new XMLLoader();
SolrInputDocument document2 = loader.readDoc(parser2);
docs.add(document1);
docs.add(document2);
Collections.shuffle(docs, random());
req.add(docs);
RequestWriter requestWriter = new RequestWriter();
OutputStream os = new ByteArrayOutputStream();
requestWriter.write(req, os);
assertBlockU(os.toString());
assertU(commit());
final SolrIndexSearcher searcher = getSearcher();
assertSingleParentOf(searcher, one("yz"), "X");
assertSingleParentOf(searcher, one("bc"), "A");
}
use of org.apache.solr.client.solrj.request.RequestWriter in project lucene-solr by apache.
the class AddBlockUpdateTest method testSolrJXML.
@SuppressWarnings("serial")
@Test
public void testSolrJXML() throws IOException {
UpdateRequest req = new UpdateRequest();
List<SolrInputDocument> docs = new ArrayList<>();
SolrInputDocument document1 = new SolrInputDocument() {
{
final String id = id();
addField("id", id);
addField("parent_s", "X");
ArrayList<SolrInputDocument> ch1 = new ArrayList<>(Arrays.asList(new SolrInputDocument() {
{
addField("id", id());
addField("child_s", "y");
}
}, new SolrInputDocument() {
{
addField("id", id());
addField("child_s", "z");
}
}));
Collections.shuffle(ch1, random());
addChildDocuments(ch1);
}
};
SolrInputDocument document2 = new SolrInputDocument() {
{
final String id = id();
addField("id", id);
addField("parent_s", "A");
addChildDocument(new SolrInputDocument() {
{
addField("id", id());
addField("child_s", "b");
}
});
addChildDocument(new SolrInputDocument() {
{
addField("id", id());
addField("child_s", "c");
}
});
}
};
docs.add(document1);
docs.add(document2);
Collections.shuffle(docs, random());
req.add(docs);
RequestWriter requestWriter = new RequestWriter();
OutputStream os = new ByteArrayOutputStream();
requestWriter.write(req, os);
assertBlockU(os.toString());
assertU(commit());
final SolrIndexSearcher searcher = getSearcher();
assertSingleParentOf(searcher, one("yz"), "X");
assertSingleParentOf(searcher, one("bc"), "A");
}
use of org.apache.solr.client.solrj.request.RequestWriter in project lucene-solr by apache.
the class BasicHttpSolrClientTest method testUpdate.
@Test
public void testUpdate() throws Exception {
DebugServlet.clear();
try (HttpSolrClient client = getHttpSolrClient(jetty.getBaseUrl().toString() + "/debug/foo")) {
UpdateRequest req = new UpdateRequest();
req.add(new SolrInputDocument());
req.setParam("a", "ሴ");
try {
client.request(req);
} catch (ParseException ignored) {
}
//default method
assertEquals("post", DebugServlet.lastMethod);
//agent
assertEquals("Solr[" + HttpSolrClient.class.getName() + "] 1.0", DebugServlet.headers.get("User-Agent"));
//default wt
assertEquals(1, DebugServlet.parameters.get(CommonParams.WT).length);
assertEquals("javabin", DebugServlet.parameters.get(CommonParams.WT)[0]);
//default version
assertEquals(1, DebugServlet.parameters.get(CommonParams.VERSION).length);
assertEquals(client.getParser().getVersion(), DebugServlet.parameters.get(CommonParams.VERSION)[0]);
//content type
assertEquals("application/javabin", DebugServlet.headers.get("Content-Type"));
//parameter encoding
assertEquals(1, DebugServlet.parameters.get("a").length);
assertEquals("ሴ", DebugServlet.parameters.get("a")[0]);
//XML response and writer
client.setParser(new XMLResponseParser());
client.setRequestWriter(new RequestWriter());
try {
client.request(req);
} catch (ParseException ignored) {
}
assertEquals("post", DebugServlet.lastMethod);
assertEquals("Solr[" + HttpSolrClient.class.getName() + "] 1.0", DebugServlet.headers.get("User-Agent"));
assertEquals(1, DebugServlet.parameters.get(CommonParams.WT).length);
assertEquals("xml", DebugServlet.parameters.get(CommonParams.WT)[0]);
assertEquals(1, DebugServlet.parameters.get(CommonParams.VERSION).length);
assertEquals(client.getParser().getVersion(), DebugServlet.parameters.get(CommonParams.VERSION)[0]);
assertEquals("application/xml; charset=UTF-8", DebugServlet.headers.get("Content-Type"));
assertEquals(1, DebugServlet.parameters.get("a").length);
assertEquals("ሴ", DebugServlet.parameters.get("a")[0]);
//javabin request
client.setParser(new BinaryResponseParser());
client.setRequestWriter(new BinaryRequestWriter());
DebugServlet.clear();
try {
client.request(req);
} catch (ParseException ignored) {
}
assertEquals("post", DebugServlet.lastMethod);
assertEquals("Solr[" + HttpSolrClient.class.getName() + "] 1.0", DebugServlet.headers.get("User-Agent"));
assertEquals(1, DebugServlet.parameters.get(CommonParams.WT).length);
assertEquals("javabin", DebugServlet.parameters.get(CommonParams.WT)[0]);
assertEquals(1, DebugServlet.parameters.get(CommonParams.VERSION).length);
assertEquals(client.getParser().getVersion(), DebugServlet.parameters.get(CommonParams.VERSION)[0]);
assertEquals("application/javabin", DebugServlet.headers.get("Content-Type"));
assertEquals(1, DebugServlet.parameters.get("a").length);
assertEquals("ሴ", DebugServlet.parameters.get("a")[0]);
}
}
use of org.apache.solr.client.solrj.request.RequestWriter in project lucene-solr by apache.
the class TestSolrJErrorHandling method testWithXml.
@Test
public void testWithXml() throws Exception {
HttpSolrClient client = (HttpSolrClient) getSolrClient();
client.setRequestWriter(new RequestWriter());
// delete everything!
client.deleteByQuery("*:*");
doIt(client);
}
use of org.apache.solr.client.solrj.request.RequestWriter in project lucene-solr by apache.
the class TestBatchUpdate method testWithXml.
@Test
public void testWithXml() throws Exception {
HttpSolrClient client = (HttpSolrClient) getSolrClient();
client.setRequestWriter(new RequestWriter());
// delete everything!
client.deleteByQuery("*:*");
doIt(client);
}
Aggregations