【轉】Solr從資料庫匯入資料(DIH)

來源:互聯網
上載者:User

標籤:

  本文轉自:http://blog.csdn.net/xiaoyu714543065/article/details/11849115

一. 資料匯入(DataImportHandler-DIH)

DIH 是solr 提供的一種針對資料庫、xml/HTTP、富文字物件匯入到solr 索引庫的工具包。這裡只針對資料庫做介紹。

A、準備以下jar包

apache-solr-dataimporthandler-4.0.0.jar

apache-solr-dataimporthandler-extras-4.0.0.jar

apache-solr-dataimportscheduler-1.1.jar(增量匯入使用)

資料庫對應的jdbc驅動包這裡使用的是Oracle oracle10g.ja放入Tomcat6.0.36/webapps/sol/WEB-INF/lib 中

B、配置solrconfig.xml

在solrconfig.xml中加入如下配置:

<requestHandlername=”/dataimport” class=”org.apache.solr.handler.dataimport.DataImportHandler”>

<lst name=”defaults”>

<str name=”config”>xx-data-config.xml</str>

</lst>

</requestHandler>

C、配置資料來源

在與solrconfig.xml檔案同級的目錄中建立上述配置中的xx-data-config.xml檔案,配置如下

query屬性為全匯入的時候使用。其他為增量匯入使用。

<?xml version=”1.0″ encoding=”UTF-8″ ?>

<dataConfig>

<dataSource type=”JdbcDataSource”

driver=”oracle.jdbc.driver.OracleDriver”

url=”jdbc:oracle:thin:@192.168.0.129:1521:orcl”

user=”username”

password=”password”/>

<document>

<entity name=”business_info” pk=”ID”

query=”select t.ID id,business_name,bussiness_type from business t”

deltaImportQuery=”select t.ID id,business_name,bussiness_type from business t where id=’${dataimporter.delta.ID}’”

deltaQuery=”select t.ID id,business_name,bussiness_type from business t where  to_char(updatetime,’yyyy-mm-dd hh24:mi:ss’)> ’${dataimporter.last_index_time}’”>

<field column=”ID” name=”id”/>

</entity>

</document>

</dataConfig>

 

至此所有DIH的配置完成,在瀏覽器中輸入命令:

全匯入:

http://localhost:8085/solr/core0/dataimport?command=full-import&commit=ture

增量匯入:

http://localhost:8085/solr/core0/dataimport?command=delta-import&clean=false&commit=ture

查看匯入狀態

http://localhost:8085/solr/core0/dataimport?command=status

D、處理CLOB欄位

<entity name=”meta” query=”select id,filename,content,bytes from documents” transformer=”ClobTransformer”>

<field column=”ID” name=”id” />

<field column=”CONTENT” name=”CONTENT” clob=”true” />

</entity>

ClOB 欄位的 column 必須大寫!!

E、DIH記憶體溢出錯誤

在使用DIH時,容易報記憶體溢出錯誤。可以通過設定jvm大小來解決。設定方法如下:

在tomcat\bin\startup.bat 加入SET JAVA_OPTS=-Xms128m -Xmx1024m 配置 這裡設定的是1024M,根據情況可以適量增大 

F、自動全匯入和自動增量匯入

此功能可以自己寫程式實現,也可利用apache-solr-dataimportscheduler-1.0.jar包完成此功能。配置如下:

修改solr.war中WEB-INF/web.xml, 在servlet節點前面增加:

<listener>
<listener-class>
org.apache.solr.handler.dataimport.scheduler.ApplicationListener
</listener-class>
</listener>

將apache-solr-dataimportscheduler-.jar 中 dataimport.properties 取出並根據實際情況修改,然後放到 solr.home/conf (不是solr.home/core/conf) 目錄下面

具體配置可參考:http://code.google.com/p/solr-dataimport-scheduler/

【轉】Solr從資料庫匯入資料(DIH)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.