2011-05-12 48 views
1

我正在調查分塊我的數據源優化數據導入到solr,並想知道是否有可能使用分段數據的主要URL。Solr DataImportHandler Chunked UrlDataSource

例如文件1可以

<chunks> 
    <chunk url="http://localhost/chunker?start=0&stop=100" /> 
    <chunk url="http://localhost/chunker?start=100&stop=200" /> 
    <chunk url="http://localhost/chunker?start=200&stop=300" /> 
    <chunk url="http://localhost/chunker?start=300&stop=400" /> 
    <chunk url="http://localhost/chunker?start=400&stop=500" /> 
    <chunk url="http://localhost/chunker?start=500&stop=600" /> 
</chunks> 

與每個塊的URL導致類似

<items> 
    <item data1="info1" /> 
    <item data1="info2" /> 
    <item data1="info3" /> 
    <item data1="info4" /> 
</iems> 

我與500+萬條記錄工作,所以我認爲,數據將需要被分塊以避免內存問題(在使用SQLEntityProcessor時遇到這個問題)。我也想避免500+百萬網頁請求的,可以讓貴我覺得

回答

6

由於缺乏在互聯網上的例子,我想我會寄我最終使用

<?xml version="1.0" encoding="utf-8"?> 
<result> 
    <dataCollection func="chunked"> 
    <data info="test" info2="test" /> 
    <data info="test" info2="test" /> 
    <data info="test" info2="test" /> 
    <data info="test" info2="test" /> 
    <data info="test" info2="test" /> 
    <data info="test" info2="test" /> 
    <data hasmore="true" nexturl="http://server.domain.com/handler?start=0&amp;end=1000000000&amp;page=1&amp;pagesize=10" 
    </dataCollection> 
</result> 

請注意,我使用指定下一頁上有更多內容並提供下一頁的網址,這一點很重要。這與Solr Documentation for DataImportHandlers一致。請注意,該文檔指定分頁的Feed應該告訴系統它有更多以及在哪裏獲得下一批。

<dataConfig> 
    <dataSource name="b" type="URLDataSource" baseUrl="http://server/" encoding="UTF-8" /> 
    <document> 
     <entity name="continue" 
       dataSource="b" 
       url="handler?start=${dataimport.request.startrecord}&amp;end=${dataimport.request.stoprecord}&amp;pagesize=100000" 
       stream="true" 
       processor="XPathEntityProcessor" 
       forEach="/result/dataCollection/data" 
       transformer="DateFormatTransformer" 
       connectionTimeout="120000" 
       readTimeout="300000" 
       > 
      <field column="id" xpath="/result/dataCollection/data/@info" /> 
      <field column="id" xpath="/result/dataCollection/data/@info" /> 
      <field column="$hasMore" xpath="/result/dataCollection/data/@hasmore" /> 
      <field column="$nextUrl" xpath="/result/dataCollection/data/@nexturl" /> 
     </entity> 
    </document> 

請注意$ hasMore和$ nextUrl字段。您可能想要放置超時。我還建議允許指定頁面大小(它有助於使用tweeking設置來獲得最佳處理速度)。我使用一臺帶有四核至強處理器和32GB內存的單一服務器上的多核(3)solr實例,每秒約記錄12.5K條記錄。

分頁結果的應用程序使用與存儲數據的SQL服務器相同的系統。當我們最終負載均衡solr服務器時,我也會通過啓動和停止位置來最小化配置更改....

1

實體可以嵌套以執行您最初想要的操作。內部實體可以參考外部字段url="${chunk.link}",其中chunk是外部實體名稱& link是字段名稱。

<?xml version="1.0" encoding="windows-1250"?> 
<dataConfig> 
    <dataSource name="b" type="URLDataSource" baseUrl="http://server/" encoding="UTF-8" /> 
    <document> 
    <entity name="chunk" 
     dataSource="b" 
     url="path/to/chunk.xml" 
     stream="true" 
     processor="XPathEntityProcessor" 
     forEach="/chunks/chunk" 
     transformer="DateFormatTransformer" 
     connectionTimeout="120000" 
     readTimeout="300000" > 
     <field column="link" xpath="/chunks/chunk/@url" /> 
     <entity name="item" 
     dataSource="b" 
     url="${chunk.link}" 
     stream="true" 
     processor="XPathEntityProcessor" 
     forEach="/items/item" 
     transformer="DateFormatTransformer" 
     connectionTimeout="120000" 
     readTimeout="300000" > 
     <field column="info" xpath="/items/item/@info" /> 
     </entity> 
    </entity> 
</document> 
</dataConfig> 
相關問題