2011-05-12 46 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> 
相关问题