设为首页 收藏本站
查看: 2975|回复: 0

[经验分享] Solr data import 中XML/HTTP 数据源的使用

[复制链接]

尚未签到

发表于 2016-12-16 11:18:57 | 显示全部楼层 |阅读模式
  

参考自:http://wiki.apache.org/solr/DataImportHandler
DataImportHandler 可以通过datasource数据源索引来自于HTTP的数据。包括REST/XML和RSS/ATOM 。
在版本1.4中,推荐使用URLDataSource。
配置示例如下:



<dataSource name="b" type="HttpDataSource" baseUrl="http://host:port/" encoding="UTF-8" connectionTimeout="5000" readTimeout="10000"/>
<!-- or in Solr 1.4-->
<dataSource name="a" type="URLDataSource" baseUrl="http://host:port/" encoding="UTF-8" connectionTimeout="5000" readTimeout="10000"/>
 datasource的属性有:
baseUrl(可选):
you should use it when the host/port changes between
Dev/QA/Prod environments. Using this attribute isolates the changes to be made
to the solrconfig.xml
encoding(可选):定义响应头里面的编码方式。这个属性可以替换掉服务器的默认编码方式。
connectionTimeout(可选):默认时间是5000ms
readTimeout(可选):默认是10000ms
 
下面是一个data-config.xml示例的配置:
这是一个Slashdot RSS feed的例子。



<dataConfig>
<dataSource type="HttpDataSource" />
<document>
<entity name="slashdot"
pk="link"
url="http://rss.slashdot.org/Slashdot/slashdot"
processor="XPathEntityProcessor"
forEach="/RDF/channel | /RDF/item"
transformer="DateFormatTransformer">
<field column="source"       xpath="/RDF/channel/title"   commonField="true" />
<field column="source-link"  xpath="/RDF/channel/link"    commonField="true" />
<field column="subject"      xpath="/RDF/channel/subject" commonField="true" />
<field column="title"        xpath="/RDF/item/title" />
<field column="link"         xpath="/RDF/item/link" />
<field column="description"  xpath="/RDF/item/description" />
<field column="creator"      xpath="/RDF/item/creator" />
<field column="item-subject" xpath="/RDF/item/subject" />
<field column="slash-department" xpath="/RDF/item/department" />
<field column="slash-section"    xpath="/RDF/item/section" />
<field column="slash-comments"   xpath="/RDF/item/comments" />
<field column="date" xpath="/RDF/item/date" dateTimeFormat="yyyy-MM-dd'T'hh:mm:ss" />
</entity>
</document>
</dataConfig>

 看到这个东西的确有点迷糊,因此下面是我们索引wikipedia的例子:
下面这个data-config.xml是用于索引http://dumps.wikimedia.org/enwiki/20100312/
这个网页下的pages-articles.xml.bz2文件,我们需要去这个网页下载该文件,解压以后放到conf/data目录下,这个文件不压缩的大小是1.50GB。



<dataConfig>
<dataSource type="FileDataSource" encoding="UTF-8" />
<document>
<entity name="page"
processor="XPathEntityProcessor"
stream="true"
forEach="/mediawiki/page/"
url="/data/enwiki-20100312-pages-articles.xml"
transformer="RegexTransformer,DateFormatTransformer"
>
<field column="id"        xpath="/mediawiki/page/id" />
<field column="title"     xpath="/mediawiki/page/title" />
<field column="revision"  xpath="/mediawiki/page/revision/id" />
<field column="user"      xpath="/mediawiki/page/revision/contributor/username" />
<field column="userId"    xpath="/mediawiki/page/revision/contributor/id" />
<field column="text"      xpath="/mediawiki/page/revision/text" />
<field column="timestamp" xpath="/mediawiki/page/revision/timestamp" dateTimeFormat="yyyy-MM-dd'T'hh:mm:ss'Z'" />
<field column="$skipDoc"  regex="^#REDIRECT .*" replaceWith="true" sourceColName="text"/>
</entity>
</document>
</dataConfig>

 注意一下上面的url最好写绝对路径,我的相对路径老是出错-_-。
相关的schema.xml文件如下:



<field name="id"        type="integer" indexed="true" stored="true" required="true"/>
<field name="title"     type="string"  indexed="true" stored="false"/>
<field name="revision"  type="sint"    indexed="true" stored="true"/>
<field name="user"      type="string"  indexed="true" stored="true"/>
<field name="userId"    type="integer" indexed="true" stored="true"/>
<field name="text"      type="text"    indexed="true" stored="false"/>
<field name="timestamp" type="date"    indexed="true" stored="true"/>
<field name="titleText" type="text"    indexed="true" stored="true"/>
...
<uniqueKey>id</uniqueKey>
<copyField source="title" dest="titleText"/>

 下面会花费数小时的时间去索引数据,并且内存使用率将持续最高,请注意很多wikipedia的文章都仅仅是指向其它文章$skipDoc(1.4)的使用可以使得这些文章被忽略,当然前提是正则表达式匹配。
请注意:由于目前唯一支持delta importEntityProcessorSqlEntityProcessor,而XPathEntityProcessor并现在没有实现delta import。如果你想实现这些方法的话,你需要修改EntityProcessor.java         

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-315146-1-1.html 上篇帖子: solr中为pdf word excel等文档做索引和存诸时如何把回车空格等去掉 下篇帖子: Solr的自动完成/自动补充实现介绍(第一部分)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表