solr MySQL database connection

A, solr search server

1.solr Overview

      Solr is an open source search platform for building search applications. itBuilt on top of Lucene (full-text search engine). Solr is an enterprise-class, fast and highly scalable. Applications built using Solr very complex, high performance can be provided.

2.solr download and install

solr official website address: https://lucene.apache.org/solr/
Here Insert Picture Description
Here Insert Picture Description

3. solr Prerequisites

Add Core choice to create a
command: window system cmd, in the bin directory of solr

cd E:\solr\solr-7.7.2\bin
//test 是我的文件夹名
solr create -c test
  1. The E: \ solr \ solr-7.7.2 \ dist ( my own directory path) in the jar: solr-dataimporthandler-7.7.2.jar and solr-dataimporthandler-extras-7.7.2.jar
    copied to E: \ solr \ solr-7.7.2 \ server \ solr-webapp \ webapp \ WEB-INF \ lib ( I own directory path)

  2. Download mysql-connector-java-5.1.30.jar copied to E (by yourself maven download): \ solr \ solr-7.7.2 \ server \ solr-webapp \ webapp \ under WEB-INF \ lib directory.

  3. The E: \ solr \ solr-7.7.2 \ server \ under solr \ test \ conf directory is managed-schema file name modified to schema.xml

Second, the MySQL database connection

1. New data-config.xml file

data-config.xml is the configuration file for the database table
my data-config.xml

<?xml version="1.0" encoding="UTF-8" ?>
<dataConfig>
    <!-- 数据库信息 -->
    <dataSource type="JdbcDataSource" 
        driver="com.mysql.jdbc.Driver" 
        url="jdbc:mysql://127.0.0.1:3306/test" 
        user="root" password="123456"/>
    <document>
         <entity name="users" pk="id"  
		        query="select * from users"
                deltaQuery="select * from users where name > '${dataimporter.last_index_time}'">
                <!-- 对应数据库表的字段 --> 
            <field column="name" name="name" />
            <field column="age" name="age" />
        </entity>
    </document>
</dataConfig>

2. Modify solrconfig.xml

Registration data-config.xml file information in the solrconfig.xml:
Here Insert Picture Description

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

3. Modify schema.xml

Add Content:

<field name="name" type="string" indexed="true" required="false" stored="true"/> 
<field name="age" type="string" indexed="true" required="true" stored="true"/>

4. Restart and view the data

Stop solr: solr stop _all
start solr: solr start

1. Import Data
Here Insert Picture Description
2. Results
Here Insert Picture Description
3. database corresponding
Here Insert Picture Description

Third, stepped pit

  1. Importing data is not successful?
    ps: In the data-config.xml configuration file, my
<field column="age" name="age" />

The value of the name value before I named myself as: name = "t_age"
and the database field is not the same, it has been queried data.

Published 16 original articles · won praise 3 · Views 525

Guess you like

Origin blog.csdn.net/outdata/article/details/103787423