Win7 Solr4.10.1 and MySQL integration (index and search)

Source: Internet
Author: User
Tags solr

1. Open the D:\webserver\solr\collection1\conf\solrconfig.xml file,<requesthandler name= "/select" class= "SOLR. Searchhandler "> Line aboveAdd the following content:

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

2. Create database-to-consumer, create table goods, add fields goods_id (int) and goods_name (varchar);

3, in the D:\webserver\solr\collection1\conf directory to create a new Data-config.xml file, the file content is as follows:

<dataConfig>
<datasource type= "Jdbcdatasource"
driver= "Com.mysql.jdbc.Driver"
url= "JDBC:MYSQL://LOCALHOST/B2C"
user= "Root"
password= "666666"/>
<document>
<entity name= "goods" query= "select Goods_id,goods_name from goods" >
<field column= "goods_id" name= "id"/>
<field column= "Goods_name" name= "Goods_name"/>
</entity>
</document>
</dataConfig>

4, copy the D:\solr-4.10.1\dist\solr-dataimporthandler-4.10.1.jar file to D:\Tomcat 8.0\webapps\solr\web-inf\lib below;

5, the MySQL Java driver package (I use Mysql-connector-java-5.1.33-bin.jar) copy to D:\Tomcat 8.0\webapps\solr\web-inf\lib;

6. Open the D:\webserver\solr\collection1\conf\schema.xml file,

(1) Retain the definition of the following fields;

<field name= "_version_" type= "Long" indexed= "true" stored= "true"/>
<field name= "_root_" type= "string" indexed= "true" stored= "false"/>

(2) Delete the definition of redundant fields;

(3) Add the following fields:

<field name= "id" type= "string" indexed= "true" stored= "true" required= "true" multivalued= "false"/>
<field name= "Goods_name" type= "Text_ik" indexed= "true" stored= "true"/>

(4) Modifying primary key fields

<uniqueKey>ID</uniqueKey>

7, visit http://127.0.0.1:8080/solr/, follow the steps of 1-6 to build index

The display on the right of the graph indicates that an index is being built, and a later refresh can be seen as shown below:

Indexing completed. added/updated:999 documents. Deleted 0 documents. (duration:01s)

Requests: 1 (1/s), fetched: 999 (999/S), skipped: 0, processed: 999 (999/S) Started: Minutes agoOK, index completed, a total of 999 data!

8. Search data

The result is OK ~~~~~~

Win7 Solr4.10.1 and MySQL integration (index and search)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.