Apache solr (2), apachesolr
In the previous article, I tried to install and configure solr and how to search for solr, today, I tried to connect solr to the MySQL database (only a single table, one-to-many, and many-to-many have yet to be studied)
1. MySQL directory structure
2. Create a New democore
3. Create a new core and field on the solr Server http: // localhost: 8983/solr visualization page. The fields of the field and the MySQL Database correspond one to one.
4. Configure solrconfig. xml, the data-config.xml is configured in our defined core, where the data-config.xml file is used to define the soling between solr and MySQL, where it uses a relative path, that is, with solrconfig. xml is in the same directory.
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler"> <lst name="defaults"> <str name="config">data-config.xml</str> </lst></requestHandler>
<?xml version='1.0' encoding='utf-8'?><dataConfig> <dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://127.0.0.1:3306/solrdemo" user="root" password="" batchSize="-1"/> <document name="democore"> <entity name="democore" pk="id" query="select * from democore"> <field column="id" name="id"/> <field column="name" name="name"/> <field column="number" name="number"/> </entity> </document></dataConfig>
5. Import the corresponding jar package to the corresponding directory.
6. import data on the Visual Interface
7. The data query shows that the import is successful.
Note: I was just getting started with solr, and the information I read on the Internet is also uneven. I don't know where to start, but I have to try a demo myself. If there is something wrong with it, please correct it. Thank you. Or where can I find something wrong? You have taken a detour. Please forgive me!