1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > solr使用网页浏览器批量导入数据库中数据(本案例是mysql)

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

时间:2021-11-14 18:45:24

相关推荐

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

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

安装solr

/u013294097/article/details/89735654

集成IKAnalyzer中文分词器

/u013294097/article/details/89735890

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

/u013294097/article/details/89739768

solr在java中的案例

/u013294097/article/details/89739859

1.依赖包下载

链接:/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">data-config.xml</str></lst></requestHandler>

添加位置,我放在/select上面(不限制位置),此处有个<str name="config">data-config.xml</>

在测试此之前,需要在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

数据库data-config.xml内容:

<?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条记录

如果觉得本文对您有所帮助,欢迎您扫码下图所示的支付宝和微信支付二维码对本文进行随意打赏。您的支持将鼓励我继续创作

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。