首页 > 代码库 > solr3.6数据导入DataImport实现
solr3.6数据导入DataImport实现
上文中介绍了定时器实现实时索引数据的解决方案,本文对其进行补充,介绍数据导入的配置
1 配置RequestHandler
<!-- DataImportHandler -->
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">db/db-data-config.xml</str>
</lst>
</requestHandler>
<lst name="defaults">
<str name="config">db/db-data-config.xml</str>
</lst>
</requestHandler>
2 配置数据源和数据实体
包括全部导入和增量导入
<dataConfig>
<dataSource driver="net.sourceforge.jtds.jdbc.Driver" url="jdbc:jtds:sqlserver://IP;instance=SQLSRV2005;DatabaseName=CloudPlat" user="sa" password="sa" batchSize="100"/>
<document>
<entity name="article" pk="DocAutoId" query="select * from CP_InfoListPub order by DocAutoId"
deltaImportQuery="select * from CP_InfoListPubClone where DocAutoId=‘${dataimporter.delta.DocAutoId}‘"
deltaQuery="select DocAutoId from CP_InfoListPubClone where Doc_GatherDate > ‘${dataimporter.last_index_time}‘"
deletedPkQuery="select DocAutoId from CP_InfoListPubClone where DocAutoId=0"
transformer="ClobTransformer,HTMLStripTransformer,DateFormatTransformer" >
<field column="DocAutoId" name="id" />
<field column="Doc_Title" name="title" />
<field column="Doc_RegionName" name="region" />
<field column="Doc_TradeName" name="trade" />
<field column="Doc_Content" name="content" clob="true" stripHTML="true"/>
<field column="Doc_PubDate" name="update" dateTimeFormat="yyyy-MM-dd"/>
<field column="Doc_Url" name="link" />
</entity>
</document>
<dataSource driver="net.sourceforge.jtds.jdbc.Driver" url="jdbc:jtds:sqlserver://IP;instance=SQLSRV2005;DatabaseName=CloudPlat" user="sa" password="sa" batchSize="100"/>
<document>
<entity name="article" pk="DocAutoId" query="select * from CP_InfoListPub order by DocAutoId"
deltaImportQuery="select * from CP_InfoListPubClone where DocAutoId=‘${dataimporter.delta.DocAutoId}‘"
deltaQuery="select DocAutoId from CP_InfoListPubClone where Doc_GatherDate > ‘${dataimporter.last_index_time}‘"
deletedPkQuery="select DocAutoId from CP_InfoListPubClone where DocAutoId=0"
transformer="ClobTransformer,HTMLStripTransformer,DateFormatTransformer" >
<field column="DocAutoId" name="id" />
<field column="Doc_Title" name="title" />
<field column="Doc_RegionName" name="region" />
<field column="Doc_TradeName" name="trade" />
<field column="Doc_Content" name="content" clob="true" stripHTML="true"/>
<field column="Doc_PubDate" name="update" dateTimeFormat="yyyy-MM-dd"/>
<field column="Doc_Url" name="link" />
</entity>
</document>
</dataConfig>
3 引入相关的文件,apache-solr-dataimporthandler-1.4.0.jar,apache-solr-dataimporthandler-extras-1.4.0.jar,mysql-connector-java-5.1.10.jar等
4 启动tomcat,访问http://localhost:8080/solr/dataimport?command=full-import 将数据全部导入solr服务器进行索引
访问http://localhost:8080/solr/dataimport?command=status可以查看运行状态
当修改data-config.xml 文件配置时运行http://localhost:8080/solr/dataimport?command=reload-config可以进行重新加载配置文件
如果想终止运行http://localhost:8080/solr/dataimport?command=abort
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。