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

[经验分享] Apache Solr 实践(二)数据库增量导入

[复制链接]

尚未签到

发表于 2016-12-16 09:06:07 | 显示全部楼层 |阅读模式
  之前将Solr的基础环境搭建了起来。今天配置一下数据库的增量导入。实现步骤wiki上面写的已经很清楚,主要注意两点,一是索引的中文分词,二是自定义字段。solr自带的schema.xml中已经配置了常用字段,遇不包含字段需要定义。依wiki,实现solr索引定时增量导入大致需五步。
  第一步,配置requesthandler于solrconfig.xml内容如下

  <requestHandler name="/dataimport"
      class="org.apache.solr.handler.dataimport.DataImportHandler">
      <lst name="defaults">
        <str name="config">./data-config.xml</str>
      </lst>
  </requestHandler>
  用到的jar包solr-dataimporthandler-4.3.0.jar位于solr-4.3.0\dist,需要拷贝到tomcat/webapps/lib下。
  第二步,编写data-config.xml和dataimport.properties。solr发布包中随带了一个demo位于solr-4.3.0\example\example-DIH\solr\db\conf直接拿来稍作修改

<dataConfig>
<dataSource driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/solr_import" user="root" password="admin"/>
<document>
<entity name="item" query="select * from item"
deltaQuery="select id from item where last_modified > '${dataimporter.last_index_time}'">
<field column="ID" name="id" />
<field column="NAME" name="name" />
<field column="MANU" name="manu" />
<field column="WEIGHT" name="weight" />
<field column="PRICE" name="price" />
<field column="POPULARITY" name="popularity" />
<field column="INSTOCK" name="inStock" />
<field column="INCLUDES" name="includes" />
<entity name="feature"  
query="select DESCRIPTION from FEATURE where ITEM_ID='${item.ID}'"
deltaQuery="select ITEM_ID from FEATURE
where last_modified > '${dataimporter.last_index_time}'"
parentDeltaQuery="select ID from item where ID=${feature.ITEM_ID}">
<field name="features" column="DESCRIPTION" />
</entity>
<entity name="item_category"
query="select CATEGORY_ID from item_category where ITEM_ID='${item.ID}'"
deltaQuery="select ITEM_ID, CATEGORY_ID from
item_category where last_modified > '${dataimporter.last_index_time}'"
parentDeltaQuery="select ID from item where ID=${item_category.ITEM_ID}">
<entity name="category"
query="select DESCRIPTION from category where ID = '${item_category.CATEGORY_ID}'"
deltaQuery="select ID from category where last_modified > '${dataimporter.last_index_time}'"
parentDeltaQuery="select ITEM_ID, CATEGORY_ID
from item_category where CATEGORY_ID=${category.ID}">
<field column="description" name="cat" />
</entity>
</entity>
</entity>
</document>
</dataConfig>

#Fri Jan 17 11:44:56 CST 2014
interval=1
port=80
server=localhost
params=/dataimport?command\=delta-import&clean\=false&commit\=true
webapp=solr
reBuildIndexInterval=2
dataimporter.last_index_time=1914-01-14 17\:40\:00
syncEnabled=1
last_index_time=2014-01-17 11\:44\:55
item.last_index_time=2014-01-17 11\:44\:55
reBuildIndexParams=/dataimport?command\=full-import&clean\=true&commit\=true
reBuildIndexBeginTime=03\:10\:00
syncCores=collection1

  第三步,修改schema.xml支持中文分词。data-config.xml中filed引用schema.xml中的filedType,而schema.xml中name,manu等字段类行为text_general,需要改为之前配置的text_zh.
  第四步建数据库,数据库脚本也都是现成的,位于solr-4.3.0\example\example-DIH\hsqldb\ex.script。demo是基于sqldb的,稍作修改即可用于mysql。将数据库驱动拷到lib。insert N笔数据(中文)作为测试。
  第五步,建索引。依次打开solr控制台-——>dataimport,command首次选full-import,勾选commit,Entity选择item——>execute。
  索引结果如何?在solr控制台左侧选择Query,q填写name:关键字,execute query。效果如图
DSC0000.png

运维网声明 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-314961-1-1.html 上篇帖子: Solr 在websphere7中部署出现javax.management.InstanceAlreadyExistsException异常 下篇帖子: Solr的facet分组
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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