Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
需要帮助使用DataImportHandler将XML文件索引到Solr中吗_Solr - Fatal编程技术网

需要帮助使用DataImportHandler将XML文件索引到Solr中吗

需要帮助使用DataImportHandler将XML文件索引到Solr中吗,solr,Solr,我不懂java,不懂XML,也不懂Lucene。现在那已经不碍事了。我一直在使用ApacheSolr/lucene创建一个小项目。我的问题是无法为xml文件编制索引。我想我知道它应该如何工作,但我可能错了。我不知道你需要什么样的信息来帮助我,所以我将只发布代码 <dataConfig> <dataSource type="FileDataSource" encoding="UTF-8" /> <document> <!-- This first enti

我不懂java,不懂XML,也不懂Lucene。现在那已经不碍事了。我一直在使用ApacheSolr/lucene创建一个小项目。我的问题是无法为xml文件编制索引。我想我知道它应该如何工作,但我可能错了。我不知道你需要什么样的信息来帮助我,所以我将只发布代码

<dataConfig>
<dataSource type="FileDataSource" encoding="UTF-8" />
<document>
<!-- This first entity block will read all xml files in baseDir and feed it into the second entity block for handling. -->
<entity name="AMMFdir" rootEntity="false" dataSource="null"
        processor="FileListEntityProcessor"
        fileName="^*\.xml$" recursive="true"
        baseDir="C:\Documents and Settings\saperez\Desktop\Tomcat\apache-tomcat-7.0.23\webapps\solr\data\AMMF_New"
        >
<entity 
        processor="XPathEntityProcessor"
        name="AMMF"
        pk="AcquirerBID"
        datasource="AMMFdir"
        url="${AMMFdir.fileAbsolutePath}"
        forEach="/AMMF/Merchants/Merchant/"
        transformer="DateFormatTransformer, RegexTransformer"
        >

    <field column="AcquirerBID" xpath="/AMMF/Merchants/Merchant/AcquirerBID" />
    <field column="AcquirerName" xpath="/AMMF/Merchants/Merchant/AcquirerName" />
    <field column="AcquirerMerchantID" xpath="/AMMF/Merchants/Merchant/AcquirerMerchantID" />

</entity>
</entity>
</document>

示例xml文件

<?xml version="1.0" encoding="utf-8"?>
<AMMF xmlns="http://tempuri.org/XMLSchema.xsd" Version="11.2" CreateDate="2011-11-07T17:05:14" ProcessorBINCIB="422443" ProcessorName="WorldPay" FileSequence="18">
<Merchants Count="153">
    <Merchant ChangeIndicator="A" LocationCountry="840">
    <AcquirerBID>10029881</AcquirerBID>
    <AcquirerName>WorldPay</AcquirerName>
    <AcquirerMerchantID>*</AcquirerMerchantID>
    <Merchant ChangeIndicator="A" LocationCountry="840">
    <AcquirerBID>10029882</AcquirerBID>
    <AcquirerName>WorldPay2</AcquirerName>
    <AcquirerMerchantID>Hello World!</AcquirerMerchantID>
</Merchant>
</Merchants>

10029881
世界薪酬
*
10029882
世界薪酬2
你好,世界!
我有这个模式

<field name="AcquirerBID" type="string" indexed="true" stored="true" required="true" /> 
<field name="AcquirerName" type="string" indexed="true" stored="true" />
<field name="AcquirerMerchantID" type="string" indexed="true" stored="true"/>

我在配置中有这个


AMMFconfig.xml

通常最好的办法是不要使用DIH。使用API和自定义脚本以您所熟悉的语言发布这些数据有多困难

这种方法的好处有两方面:

  • 你对你的系统了解得更多,也更了解它
  • 你不会花时间去理解DIH

  • 缺点是你有点发明了轮子,但是DIH是一件很难理解的事情。

    示例XML格式不好。这可能解释了索引文件时出现的错误:

    $ xmllint sample.xml
    sample.xml:13: parser error : expected '>'
    </Merchants>
              ^
    sample.xml:14: parser error : Premature end of data in tag Merchants line 3
    sample.xml:14: parser error : Premature end of data in tag AMMF line 2
    

    Groovy是一种不需要编译的Java脚本语言。它与DIH配置文件一样易于维护。

    要了解DIH XML导入的工作原理,我建议您首先仔细阅读DIH wiki中的本章:

    在浏览器中打开Slashdot链接,然后右键单击页面并选择“查看源”。本例中使用了XML文件。 将其与DIH示例中的XPathEntityProcessor配置进行比较,您将看到在Solr中导入任何XML文件是多么容易


    如果您需要更多帮助,请询问……

    我认为编码是Solr的一项要求。我无法想象如果工具箱中没有一种语言,你能做很多事情。
    $ xmllint sample.xml
    sample.xml:13: parser error : expected '>'
    </Merchants>
              ^
    sample.xml:14: parser error : Premature end of data in tag Merchants line 3
    sample.xml:14: parser error : Premature end of data in tag AMMF line 2
    
    <?xml version="1.0" encoding="utf-8"?>
    <AMMF xmlns="http://tempuri.org/XMLSchema.xsd" Version="11.2" CreateDate="2011-11-07T17:05:14" ProcessorBINCIB="422443" ProcessorName="WorldPay" FileSequence="18">
      <Merchants Count="153">
        <Merchant ChangeIndicator="A" LocationCountry="840">
          <AcquirerBID>10029881</AcquirerBID>
          <AcquirerName>WorldPay</AcquirerName>
          <AcquirerMerchantID>*</AcquirerMerchantID>
        </Merchant>
        <Merchant ChangeIndicator="A" LocationCountry="840">
          <AcquirerBID>10029882</AcquirerBID>
          <AcquirerName>WorldPay2</AcquirerName>
          <AcquirerMerchantID>Hello World!</AcquirerMerchantID>
        </Merchant>
      </Merchants>
    </AMMF>
    
    //
    // Dependencies
    // ============
    import org.apache.solr.client.solrj.SolrServer
    import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer
    import org.apache.solr.common.SolrInputDocument
    
    @Grapes([
        @Grab(group='org.apache.solr', module='solr-solrj', version='3.5.0'),
    ])
    
    //
    // Main
    // =====
    
    SolrServer server = new CommonsHttpSolrServer("http://localhost:8983/solr/");
    def i = 1
    
    new File(".").eachFileMatch(~/.*\.xml/) { 
    
        it.withReader { reader ->
            def ammf = new XmlSlurper().parse(reader)
    
            ammf.Merchants.Merchant.each { merchant ->
                SolrInputDocument doc = new SolrInputDocument();
    
                doc.addField("id",           i++)
                doc.addField("bid_s",        merchant.AcquirerBID)
                doc.addField("name_s",       merchant.AcquirerName)
                doc.addField("merchantId_s", merchant.AcquirerMerchantID)
    
                server.add(doc)
            }
        }
    
    }
    
    server.commit()