Search in sources :

Example 1 with XMLLoader

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;
}
Also used : ContentStreamLoader(org.apache.solr.handler.loader.ContentStreamLoader) HashMap(java.util.HashMap) CSVLoader(org.apache.solr.handler.loader.CSVLoader) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrParams(org.apache.solr.common.params.SolrParams) MapSolrParams(org.apache.solr.common.params.MapSolrParams) JsonLoader(org.apache.solr.handler.loader.JsonLoader) JavabinLoader(org.apache.solr.handler.loader.JavabinLoader) XMLLoader(org.apache.solr.handler.loader.XMLLoader)

Example 2 with XMLLoader

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");
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) XMLStreamReader(javax.xml.stream.XMLStreamReader) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) OutputStream(java.io.OutputStream) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) ArrayList(java.util.ArrayList) StringReader(java.io.StringReader) RequestWriter(org.apache.solr.client.solrj.request.RequestWriter) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher) XMLLoader(org.apache.solr.handler.loader.XMLLoader) Test(org.junit.Test)

Example 3 with XMLLoader

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();
}
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 4 with XMLLoader

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();
}
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 5 with XMLLoader

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

Aggregations

XMLLoader (org.apache.solr.handler.loader.XMLLoader)8 Test (org.junit.Test)6 ContentStreamBase (org.apache.solr.common.util.ContentStreamBase)4 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)4 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)3 AddUpdateCommand (org.apache.solr.update.AddUpdateCommand)3 BufferingRequestProcessor (org.apache.solr.update.processor.BufferingRequestProcessor)3 StringReader (java.io.StringReader)2 XMLStreamReader (javax.xml.stream.XMLStreamReader)2 SolrInputDocument (org.apache.solr.common.SolrInputDocument)2 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)2 CSVLoader (org.apache.solr.handler.loader.CSVLoader)2 JavabinLoader (org.apache.solr.handler.loader.JavabinLoader)2 JsonLoader (org.apache.solr.handler.loader.JsonLoader)2 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)1 RequestWriter (org.apache.solr.client.solrj.request.RequestWriter)1 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)1