簡體   English   中英

Solr DataImportHandler不適用於XML文件

[英]Solr DataImportHandler doesn't work with XML Files

我是Solr的新手。 我通過DIH成功索引了我的sql數據庫中的數據。 現在,我想導入xml文件並通過DIH將它們編入索引,但這根本行不通! 我的data-config.xml看起來像這樣:

<dataConfig>
    <dataSource type="FileDataSource" encoding="UTF-8" />
    <document>
    <entity name="dir" 
            processor="FileListEntityProcessor" 
            baseDir="/bla/test2" 
            fileName=".*xml"
            stream="true"
            recursive="false"       
            rootEntity="false">
            <entity name="PubmedArticle"
                    processor="XPathEntityProcessor"
                    transformer="RegexTransformer"
                    stream="true"
                    forEach="/PubmedArticle"
                    url="${dir.fileAbsolutePath}">


                <field column="journal" xpath="//Name[.='journal']/following-sibling::Value/text()" />
                <field column="authors" xpath="//Name[.='authors']/following-sibling::Value/text()" />

             ..etc

而且我在schema.xml中具有以下字段:

<field name="journal" type="text" indexed="true" stored="true" required="true" /> <field name="authors" type="text" indexed="true" stored="true" required="true" />

當我運行Solr時,我沒有收到任何錯誤,也沒有索引任何文檔:

<str name="Total **Rows Fetched**">**2000**</str>
<str name="Total **Documents Skipped**">**0**</str>
<str name="Full Dump Started">2012-02-01 14:59:17</str>
<str name="">Indexing completed. **Added/Updated: 0 documents.** Deleted 0 documents.

誰能告訴我我做錯了嗎? 我什至仔細檢查了路徑語法...

我最近在嘗試相同的事情時遇到了相同的問題。 即,當使用FileListEntityProcessor (讀取多個本地.xml文件)和XPathEntityProcessor (獲取某些XML元素)時。

根本原因 :在此行中:

<field column="journal" xpath="//Name[.='journal']/following-sibling::Value/text()" />

說明 :xpath屬性(“ // Name ...”)的參數雖然有效,但xpath語法不受Solr支持。 “ Apache Solr 4.4參考指南”只是說: XPath表達式將從該字段的記錄中提取內容。 僅支持Xpath語法的子集。

解決方案 :將xpath的參數更改為文檔根目錄的完整路徑:

<field column="journal" xpath="/full/path/from/root/of/document/Name[.='journal']/following-sibling::Value/text()" />

我建議您回顧一下類似問題的答案:

需要幫助使用DataImportHandler將XML文件索引到Solr中

使用諸如groovy之類的腳本語言要簡單得多,並且更容易測試。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM