首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

Apache Solr 实践(2)数据库增量导入

2014-01-22 
Apache Solr 实践(二)数据库增量导入? requestHandler name/dataimport ??namecodedataConfigd

Apache Solr 实践(二)数据库增量导入
? <requestHandler name="/dataimport" ?? name="code"><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 2014interval=1port=80server=localhostparams=/dataimport?command\=delta-import&clean\=false&commit\=truewebapp=solrreBuildIndexInterval=2dataimporter.last_index_time=1914-01-14 17\:40\:00syncEnabled=1last_index_time=2014-01-17 11\:44\:55item.last_index_time=2014-01-17 11\:44\:55reBuildIndexParams=/dataimport?command\=full-import&clean\=true&commit\=truereBuildIndexBeginTime=03\:10\:00syncCores=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。效果如图

?Apache Solr 实践(2)数据库增量导入

?

?

?

?

?

?

?

?

热点排行