• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java XMLLoader类的典型用法和代码示例

java 1次浏览

本文整理汇总了Java中org.apache.solr.handler.loader.XMLLoader的典型用法代码示例。如果您正苦于以下问题:Java XMLLoader类的具体用法?Java XMLLoader怎么用?Java XMLLoader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

XMLLoader类属于org.apache.solr.handler.loader包,在下文中一共展示了XMLLoader类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testRequestParams

点赞 3

import org.apache.solr.handler.loader.XMLLoader; //导入依赖的package包/类
@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();
}
 

开发者ID:europeana,
项目名称:search,
代码行数:24,
代码来源:XmlUpdateRequestHandlerTest.java

示例2: testExternalEntities

点赞 3

import org.apache.solr.handler.loader.XMLLoader; //导入依赖的package包/类
@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();
}
 

开发者ID:europeana,
项目名称:search,
代码行数:26,
代码来源:XmlUpdateRequestHandlerTest.java

示例3: createDefaultLoaders

点赞 2

import org.apache.solr.handler.loader.XMLLoader; //导入依赖的package包/类
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") );
  return registry;
}
 

开发者ID:europeana,
项目名称:search,
代码行数:16,
代码来源:UpdateRequestHandler.java

示例4: testReadDoc

点赞 2

import org.apache.solr.handler.loader.XMLLoader; //导入依赖的package包/类
@Test
public void testReadDoc() throws Exception
{
  String xml = 
    "<doc boost=\"5.5\">" +
    "  <field name=\"id\" boost=\"2.2\">12345</field>" +
    "  <field name=\"name\">kitten</field>" +
    "  <field name=\"cat\" boost=\"3\">aaa</field>" +
    "  <field name=\"cat\" boost=\"4\">bbb</field>" +
    "  <field name=\"cat\" boost=\"5\">bbb</field>" +
    "  <field name=\"ab\">a&amp;b</field>" +
    "</doc>";

  XMLStreamReader parser = 
    inputFactory.createXMLStreamReader( new StringReader( xml ) );
  parser.next(); // read the START document...
  //null for the processor is all right here
  XMLLoader loader = new XMLLoader();
  SolrInputDocument doc = loader.readDoc( parser );
  
  // Read boosts
  assertEquals( 5.5f, doc.getDocumentBoost(), 0.1);
  assertEquals( 1.0f, doc.getField( "name" ).getBoost(), 0.1);
  assertEquals( 2.2f, doc.getField( "id" ).getBoost(), 0.1);
  // Boost is the product of each value
  assertEquals( (3*4*5.0f), doc.getField( "cat" ).getBoost(), 0.1);
  
  // Read values
  assertEquals( "12345", doc.getField( "id" ).getValue() );
  assertEquals( "kitten", doc.getField( "name").getValue() );
  assertEquals( "a&b", doc.getField( "ab").getValue() ); // read something with escaped characters
  
  Collection<Object> out = doc.getField( "cat" ).getValues();
  assertEquals( 3, out.size() );
  assertEquals( "[aaa, bbb, bbb]", out.toString() );
}
 

开发者ID:europeana,
项目名称:search,
代码行数:37,
代码来源:XmlUpdateRequestHandlerTest.java

示例5: testReadDelete

点赞 2

import org.apache.solr.handler.loader.XMLLoader; //导入依赖的package包/类
@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>" +
      "</update>";

    MockUpdateRequestProcessor p = new MockUpdateRequestProcessor(null);
    p.expectDelete(null, "id:150", -1);
    p.expectDelete("150", null, -1);
    p.expectDelete("200", null, -1);
    p.expectDelete(null, "id:200", -1);
    p.expectDelete(null, "id:150", 500);
    p.expectDelete("150", null, -1);

    XMLLoader loader = new XMLLoader().init(null);
    loader.load(req(), new SolrQueryResponse(), new ContentStreamBase.StringStream(xml), p);

    p.assertNoCommandsPending();
  }
 

开发者ID:europeana,
项目名称:search,
代码行数:32,
代码来源:XmlUpdateRequestHandlerTest.java

示例6: testEntities

点赞 2

import org.apache.solr.handler.loader.XMLLoader; //导入依赖的package包/类
@Test
public void testEntities() throws Exception
{
  // use a binary file, so when it's loaded fail with XML eror:
  String file = getFile("mailing_lists.pdf").toURI().toASCIIString();
  String xml = 
    "<?xml version=\"1.0\"?>" +
    "<!DOCTYPE foo [" + 
    // check that external entities are not resolved!
    "<!ENTITY bar SYSTEM \""+file+"\">"+
    // but named entities should be
    "<!ENTITY wacky \"zzz\">"+
    "]>" +
    "<random>" +
    " &bar;" +
    " <document>" +
    "  <node name=\"id\" value=\"12345\"/>" +
    "  <node name=\"foo_s\" value=\"&wacky;\"/>" +
    " </document>" +
    "</random>";
  SolrQueryRequest req = req(CommonParams.TR, "xsl-update-handler-test.xsl");
  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());
  assertEquals("zzz", add.solrDoc.getField("foo_s").getFirstValue());
  req.close();
}
 

开发者ID:europeana,
项目名称:search,
代码行数:32,
代码来源:XsltUpdateRequestHandlerTest.java

示例7: createDefaultLoaders

点赞 2

import org.apache.solr.handler.loader.XMLLoader; //导入依赖的package包/类
protected Map<String,ContentStreamLoader> createDefaultLoaders(NamedList args) {
  SolrParams p = null;
  if(args!=null) {
    p = SolrParams.toSolrParams(args);
  }
  Map<String,ContentStreamLoader> registry = new HashMap<String,ContentStreamLoader>();
  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") );
  return registry;
}
 

开发者ID:pkarmstr,
项目名称:NYBC,
代码行数:16,
代码来源:UpdateRequestHandler.java

示例8: testXML

点赞 2

import org.apache.solr.handler.loader.XMLLoader; //导入依赖的package包/类
@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 ) );
   parser.next(); // read the START document...
   //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 ) );
     parser2.next(); // read the START document...
     //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");
      
 }
 

开发者ID:europeana,
项目名称:search,
代码行数:69,
代码来源:AddBlockUpdateTest.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)