Solr7.4导入MySQL的数据

为找到多一点的数据,就在百度上搜索了一下电商的模拟数据,其中有一个tb_item表的列如下
Solr7.4导入MySQL的数据_第1张图片
配置Solr 连接MySQL,首先在D:\server\solr-7.4.0\dist目录下
复制如下的jar包

这里写图片描述
复制到
D:\server\solr-7.4.0\server\solr-webapp\webapp\WEB-INF\lib

再到
https://search.maven.org/search?q=mysql-connector下载mysql-connector
这里写图片描述
复制到D:\server\solr-7.4.0\server\solr-webapp\webapp\WEB-INF\lib目录下

在D:\server\solr-7.4.0\server\solr\lhc_core\conf配置数据库文件信息


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

创建data-config.xml文件

配置data-config.xml


<dataConfig>
<dataSource typ="JdbcDataSource"
    driver="com.mysql.jdbc.Driver"
    url="jdbc:mysql://120.772.245.224:3307/taotao?useSSL=true&verifyServerCertificate=false&allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8"
    user="root"
    password="lhc123"
/>
<document>
    
    <entity dataSource="JdbcDataSource" name="tb_item" query="SELECT id,title,sell_point,price,num,barcode,image, cid,status,created,updated from tb_item; " >
     
        <field column="id" name="id"/>
        <field column="title" name="product_title"/>
        <field column="sell_point" name="product_sell_point"/>
        <field column="price" name="product_price"/>
        <field column="num" name="product_num"/>
        <field column="image" name="product_image"/>
        <field column="cid" name="product_cid"/>
        <field column="status" name="product_status"/>
        <field column="created" name="product_created"/>
        <field column="updated" name="product_updated"/>

    entity>

document>

dataConfig>

在managed-schema中配置字段检索使用的分词器


<field name="product_title" type="text_ik" indexed="true" stored="true" />
<field name="product_sell_point" type="text_ik" indexed="true" stored="true" />
<field name="product_price" type="string" indexed="true" stored="true" />
<field name="product_num" type="string" indexed="true" stored="true" />
<field name="product_image" type="string" indexed="true" stored="true" />
<field name="product_cid" type="string" indexed="true" stored="true" />
<field name="product_status" type="string" indexed="true" stored="true" />
<field name="product_created" type="string" indexed="true" stored="true" />
<field name="product_updated" type="string" indexed="true" stored="true" />

接下来导入数据
Solr7.4导入MySQL的数据_第2张图片
execute 后可以不断点击refresh status查看导入的情况,solr导入数据还是很快

接下来就可以点击query查询了
Solr7.4导入MySQL的数据_第3张图片
可以看到导入数据成功

你可能感兴趣的:(Solr)