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.查询

 

posted @   ~沐风  阅读(267)  评论(0编辑  收藏  举报
编辑推荐:
· 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框架的用法!

喜欢请打赏

扫描二维码打赏

了解更多

点击右上角即可分享
微信分享提示