[SOLR]-database Import

Source: Internet
Author: User
Tags solr

The MySQL test is used here.

1, first build a table in MySQL: solr_test

2. Insert several test data:

3, use Notepad to play solrconfig.xml files, in the Solrhome folder. E:\solrhome\mycore\conf\solrconfig.xml

(Solrhome folder is what, see: http://www.cnblogs.com/HD/p/3977799.html)

Join this node:

 <RequestHandlername= "/dataimport"class= "Org.apache.solr.handler.dataimport.DataImportHandler">        <LSTname= "Defaults">            <Strname= "config">Data-config.xml</Str>        </LST></RequestHandler>

4, create a new Data-config.xml file, and solrconfig.xml the same directory. Content is

<Dataconfig>    <DataSourcetype= "Jdbcdatasource"Driver= "Com.mysql.jdbc.Driver"URL= "Jdbc:mysql://localhost/test"User= "root"Password= "root" />    <Document>        <Entityname= "Solr_test"Transformer= "Dateformattransformer"Query= "SELECT id, subject, content, last_update_time from solr_test WHERE ID >= ${dataimporter.request.id}">            <Fieldcolumn= ' Last_update_time 'DateTimeFormat= ' Yyyy-mm-dd HH:mm:ss ' />        </Entity>    </Document></Dataconfig>

Note: A ${dataimporter.request.id} is used here, which is the parameter, which is used when the data is imported, and the datum is read by this condition.

5. Copy extracted SOLR jar packages Solr-dataimporthandler-4.10.0.jar and Solr-dataimporthandler-extras-4.10.0.jar to Tomcat SOLR WebApp in the Web-inf\lib directory.

Of course, it also includes the JDBC jar package for MySQL: Mysql-connector-java-5.1.7-bin.jar

(Another way is to add the Lib node to the Solrconfig.xml and then put the jar package under solrhome so that the jar package is not added to the Web-inf\lib)

6, open schema.xml with Notepad, in the Solrhome folder (with the 3rd). The contents are:

<?XML version= "1.0"?><Schemaname= "My Core"version= "1.1">    <FieldTypename= "string"class= "SOLR." Strfield "Sortmissinglast= "true"omitnorms= "true"/>    <FieldTypename= "Long"class= "SOLR." Trielongfield "Precisionstep= "0"Positionincrementgap= "0"/>    <FieldTypename= "Date"class= "SOLR." Triedatefield "Precisionstep= "0"Positionincrementgap= "0"/>    <FieldTypename= "TEXT_CN"class= "SOLR." TextField ">        <Analyzertype= "Index"class= "Org.wltea.analyzer.lucene.IKAnalyzer" />        <Analyzertype= "Query"class= "Org.wltea.analyzer.lucene.IKAnalyzer" />    </FieldType>        <!-- General -    <Fieldname= "id"type= "string"indexed= "true"stored= "true"multivalued= "false"Required= "true"/>    <Fieldname= "Subject"type= "TEXT_CN"indexed= "true"stored= "true" />    <Fieldname= "Content"type= "TEXT_CN"indexed= "true"stored= "true" />    <Fieldname= "Last_update_time"type= "Date"indexed= "true"stored= "true" />    <Fieldname= "_version_"type= "Long"indexed= "true"stored= "true"/>     <!--field to determine and enforce document uniqueness. -     <UniqueKey>Id</UniqueKey>     <!--field for the Queryparser-use if an explicit fieldname is absent -     <Defaultsearchfield>Subject</Defaultsearchfield>     <!--solrqueryparser configuration:defaultoperator= "And|or" -     <SolrqueryparserDefaultoperator= "OR"/></Schema>

7. Open the SOLR Web:

Description

Custom parameters fills in the id=1, which is the parameter set in the 4th.

The clean option refers to whether to delete data that does not match. That is, not in the database select result, but the SOLR Index library exists, then delete.

You can also use this address to access directly:

Http://localhost:8899/solr/mycore/dataimport?command=full-import&clean=true&commit=true  &wt=json&indent=true&entity=solr_test&verbose=false&optimize=false  &debug=false&id=1        

The result will be returned:

After the configuration, we only need to use this URL address, you can not segment to import data to index. (as simple as this)

8. Test query:

Of course, DataImport can add parameter commands and let them reload Data-config.xml

Http://localhost:8899/solr/#/mycore/dataimport/command=reload-config

[SOLR]-database Import

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.