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.
##2. Use DataImportHandler to import and index data
Configure $SOLR_HOME\collection1\ conf\solrconfig.xmlAdd a dataimport processing Handler in front of
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:
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.
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.
After completing the settings, click Execute.
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!