solr使用网页浏览器批量导入数据库中数据(本案例是mysql)

star2017 1年前 ⋅ 1938 阅读

如果想要知道如何安装solr,集成IKAnalyzer中文分词器,批量导入数据库数据,java使用参照以下本博主博文:

安装solr

https://blog.csdn.net/u013294097/article/details/89735654

集成IKAnalyzer中文分词器

https://blog.csdn.net/u013294097/article/details/89735890

solr使用浏览器批量导入数据库中数据

https://blog.csdn.net/u013294097/article/details/89739768

solr在java中的案例

https://blog.csdn.net/u013294097/article/details/89739859

1.依赖包下载

链接:https://pan.baidu.com/s/1z9kA1eGrorQGzhmILQxVFQ 
提取码:9igo 

1为mysql驱动,2为dataimprt包

2.将以上3个包复制到solrhome/collection1/lib,如果没有这个文件夹(/lib文件夹),请自行创建(我是自己创建的)

3.配置solrconfig.xml,添加一个requestHandler,文件位置solrhome/collection1/conf。

<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
    <lst name="defaults">
      <str name="config">></str>
     </lst>
  </requestHandler> 

添加位置,我放在/select上面(不限制位置),此处有个<str name="config"> contenteditable="false" role="region" aria-label=" 图像 小部件">

在测试此之前,需要在schema.xml中添加新的域,文件位置solrhome/collection1/conf/schema.xml

	<!--product-->
   <field name="product_name" type="text_ik" indexed="true" stored="true"/>
   <field name="product_price"  type="float" indexed="true" stored="true"/>
   <field name="product_description" type="text_ik" indexed="true" stored="false" />
   <field name="product_picture" type="string" indexed="false" stored="true" />
   <field name="product_catalog_name" type="string" indexed="true" stored="true" />

   <field name="product_keywords" type="text_ik" indexed="true" stored="false" multiValued="true"/>
   <copyField source="product_name" dest="product_keywords"/>
   <copyField source="product_description" dest="product_keywords"/>

还有就是将lucene.sql文件导入mysql中

我这里使用的是navicat打开的。

再就是说需要创建一个数据库连接,以及数据库查询的xml文件,文件放置位置同上面文件位置solrhome/collection1/conf


数据库 contenteditable="false" role="region" aria-label="代码段 小部件">

<?xml version="1.0" encoding="UTF-8" ?>  
<dataConfig>   
<dataSource type="JdbcDataSource"   
		  driver="com.mysql.jdbc.Driver"   
		  url="jdbc:mysql://localhost:3306/solr"   
		  user="root"   
		  password="root"/>   
<document>   
	<entity name="product" query="SELECT pid,name,catalog_name,price,description,picture FROM products ">
		 <field column="pid" name="id"/> 
		 <field column="name" name="product_name"/> 
		 <field column="catalog_name" name="product_catalog_name"/> 
		 <field column="price" name="product_price"/> 
		 <field column="description" name="product_description"/> 
		 <field column="picture" name="product_picture"/> 
	</entity>   
</document>   
</dataConfig>

4.重启tomcat

点击execute导入数据库中的数据,验证是否成功,此处我导入成功3803条记录


更多内容请访问:IT源点

相关文章推荐

全部评论: 0

    我有话说: