use of org.apache.solr.handler.loader.XMLLoader in project lucene-solr by apache.
the class UpdateRequestHandler method createDefaultLoaders.
protected Map<String, ContentStreamLoader> createDefaultLoaders(NamedList args) {
SolrParams p = null;
if (args != null) {
p = SolrParams.toSolrParams(args);
}
Map<String, ContentStreamLoader> registry = new HashMap<>();
registry.put("application/xml", new XMLLoader().init(p));
registry.put("application/json", new JsonLoader().init(p));
registry.put("application/csv", new CSVLoader().init(p));
registry.put("application/javabin", new JavabinLoader().init(p));
registry.put("text/csv", registry.get("application/csv"));
registry.put("text/xml", registry.get("application/xml"));
registry.put("text/json", registry.get("application/json"));
pathVsLoaders.put(JSON_PATH, registry.get("application/json"));
pathVsLoaders.put(DOC_PATH, registry.get("application/json"));
pathVsLoaders.put(CSV_PATH, registry.get("application/csv"));
pathVsLoaders.put(BIN_PATH, registry.get("application/javabin"));
return registry;
}
use of org.apache.solr.handler.loader.XMLLoader 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.handler.loader.XMLLoader 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.handler.loader.XMLLoader 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.handler.loader.XMLLoader in project lucene-solr by apache.
the class XmlUpdateRequestHandlerTest method testReadDelete.
@Test
public void testReadDelete() throws Exception {
String xml = "<update>" + " <delete>" + " <query>id:150</query>" + " <id>150</id>" + " <id>200</id>" + " <query>id:200</query>" + " </delete>" + " <delete commitWithin=\"500\">" + " <query>id:150</query>" + " </delete>" + " <delete>" + " <id>150</id>" + " </delete>" + " <delete>" + " <id version=\"42\">300</id>" + " </delete>" + " <delete>" + " <id _route_=\"shard1\">400</id>" + " </delete>" + " <delete>" + " <id _route_=\"shard1\" version=\"42\">500</id>" + " </delete>" + "</update>";
MockUpdateRequestProcessor p = new MockUpdateRequestProcessor(null);
p.expectDelete(null, "id:150", -1, 0, null);
p.expectDelete("150", null, -1, 0, null);
p.expectDelete("200", null, -1, 0, null);
p.expectDelete(null, "id:200", -1, 0, null);
p.expectDelete(null, "id:150", 500, 0, null);
p.expectDelete("150", null, -1, 0, null);
p.expectDelete("300", null, -1, 42, null);
p.expectDelete("400", null, -1, 0, "shard1");
p.expectDelete("500", null, -1, 42, "shard1");
XMLLoader loader = new XMLLoader().init(null);
loader.load(req(), new SolrQueryResponse(), new ContentStreamBase.StringStream(xml), p);
p.assertNoCommandsPending();
}
Aggregations