Windows系统环境下Solr之Java实战(二)配置从MySQL数据库批量导入索引
1.将D:\JavaWeb\Solr\solr-6.2.0\dist下面的solr-dataimporthandler-6.2.0.jar和solr-dataimporthandler-extras-6.2.0.jar2个包导入到
D:\JavaWeb\Solr\solrhome\new_core\lib文件夹下面
2.将mysql-connector-java-5.1.7-bin.jar导入到D:\JavaWeb\Solr\solrhome\new_core\lib文件夹下面
3.在D:\JavaWeb\Solr\solrhome\new_core\conf\solrconfig.xml配置文件里面增加如下配置
<!-- the dataimport requestHandler --> <requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler"> <lst name="defaults"> <str name="config">data-config.xml</str> </lst> </requestHandler>
4.在D:\JavaWeb\Solr\solrhome\new_core\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/lucene?characterEncoding=utf-8" user="root" password="root" batchSize="-1" /> <document> <entity name="product" query="select pid,name,catalog,catalog_name,price,number,description,picture,release_time 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>
5.在D:\JavaWeb\Solr\solrhome\new_core\conf\managed-schema配置文件里面新增如下配置
<!--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"/>
6.创建索引
7.查询
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!