Home > Database > Mysql Tutorial > body text

How to index MySql database using Solr?

黄舟
Release: 2017-08-03 09:18:18
Original
1668 people have browsed it

The previous article introduced the deployment of solr4.10 and solr4.10 integrated IK analyzer word segmenter in tomcat. Now we will introduce how to configure solr to index the MySQL database data, so as to realize the query of the MySQL database.

First of all, you need to download the jar package needed to connect to MySQL. What I downloaded is: mysql-connector-java-5.1.26-bin.jar.

1. It is assumed that the MySQL database related work such as database, table, field definition, etc. has been completed in advance. Here is an introduction to the database used in my test case: the database and table names are crawler, the user name is root, and the password is admin. The sql statements are not listed here, it is a test anyway. In addition, because the decompression path of Solr and the path of Solr_HOME are different for everyone, I will use $SOLR_HOME to represent the path of Solr_HOME in the future.

How to index MySql database using Solr?

##2. Use DataImportHandler to import and index data

Configure $SOLR_HOME\collection1\ conf\solrconfig.xml

Add a dataimport processing Handler in front of , as shown in the figure:

Among them, the data-config.xml file is used to define the mapping relationship between solr and MySQL. The relative path used here is the same directory as solrconfig.xml. Therefore, create the data-config.xml file in the $SOLR_HOME\collection1\conf directory

How to index MySql database using Solr?

3. Pass data-config.xml Complete the mapping between Solr and MySQL database. The content of the data-config.xml file is as shown in the figure:

How to index MySql database using Solr?


##4.

Modify the schema.xml file, because this file was copied from the compressed package and contains a lot of redundant data. Here we only need to The fields related to the MySQL database table are defined in the file. Just remove the irrelevant fields. However, it should be noted that some fields still need to be retained, such as: _version_ and text. These two fields should be retained, and other fields and CopyFields should be deleted. That’s it: as shown in the picture. In the above picture, my id is defined as int type. By default, the primary key of the index in Solr only supports type="string" string type. Solution: Modify elevate.xml in the same directory and comment out the following 2 lines.

How to index MySql database using Solr?

How to index MySql database using Solr?

5. Replace mysql-connector-java-5.1.26-bin.jar and solr-4.10.3\ dist\solr-dataimporthandler-4.10.3.jar is copied to D:\Solr\solr-4.10.3\example\solr-webapp\webapp\WEB-INF\lib.


6. Open tomcat and enter Solr’s Admin UI interface, select collection1 in the Core Selector, and select the dataImport submenu. as the picture shows.

After completing the settings, click Execute.

How to index MySql database using Solr?

7. For query testing, select Query in the submenu below the core selector and enter content: Xi Jinping in the q box , click below and you will get the query results


The above is the detailed content of How to index MySql database using Solr?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!