In this paper, we simply tell SOLR to build a full-text index, import data from a database, generate an index file, this article is built in the case of the SOLR application has been set up, if you want to know how to deploy SOLR services can first look at the article: SOLR installation
Environment: JDK 7,solr4.10.1, Tomcat 7
Attached: Reference Document address: Http://wiki.apache.org/solr/DataImportHandler
1, first introduce dataimport path in Solrconfig.xml: E:\solr\example\solr\collection1\conf
<RequestHandlername= "/dataimport"class= "Org.apache.solr.handler.dataimport.DataImportHandler"> <LSTname= "Defaults"> <Strname= "config">Data-config.xml</Str> </LST> </RequestHandler>
If you do not know where to add, you can search directly RequestHandler there is a name= "/select" of the addition to the above can
2, establish data-config.xml, that is, the database configuration information just introduced, according to the configuration and solrconfig.xml in the same directory
<?XML version= "1.0" encoding= "Utf-8"?> <Dataconfig> <DataSourcetype= "Jdbcdatasource"Driver= "Com.mysql.jdbc.Driver"URL= "Jdbc:mysql://localhost:3306/test"User= "root"Password= "root"/> <Documentname= "Product"> <Entityname= "Product"PK= "id"Query= "SELECT * from _product"> <Fieldcolumn= "id"name= "id" /> <Fieldcolumn= "Name"name= "Name" /> <Fieldcolumn= "keywords"name= "keywords" /> <Fieldcolumn= "Intro"name= "Intro" /> <Fieldcolumn= "description"name= "description" /> <Fieldcolumn= "SN"name= "SN" /> </Entity> </Document> </Dataconfig>
Configure database information, configure the document to be queried
3, according to the configuration of the document just now add field configuration in Schema.xml, about the configuration of the field is not introduced here first
<!--For csop product <field name= "id" type= "string" indexed= "true" stored= "true"/> <field name= "Name" type= "string" indexed= "true" stored= "true"/> <field name= "keywords" type= "string" indexed = "true" stored= "true"/> <field name= "description" type= "string" indexed= "true" stored= "true"/> - <Fieldname= "Intro"type= "string"indexed= "true"stored= "true" /> <Fieldname= "SN"type= "string"indexed= "true"stored= "true" /> <!--For Csop product over -
Because some of the fields in SOLR default configuration are already given, you do not need to add
4, add jar Package
A, adding the MySQL driver jar package to SOLR, which is the SOLR application of the deployed Tomcat: \webapps\solr\web-inf\lib
b, add the DataImport jar package to SOLR, DataImport the package location E:\solr\dist\solr-dataimporthandler-4.10.1.jar
5, restart Tomcat
6, Access Http://localhost:8983/solr/#/collection1/dataimport//dataimport (same as manual click), export Index file
7, query validation
SOLR Connection Database Import data