SOLR dih Batch index for data source with MySQL

Source: Internet
Author: User
Tags html tags solr

Demonstrates the method of batch indexing using the SOLR admin backend, MySQL as the data source tested on:SOLR 4.5.1, mmseg4j 1.9.1, Jdk 1.6.0_45, Tomcat 6.0.37 | CentOS 5.7

Configure the data source

[Email protected] ~]# cd/root/solr-4.5.1/example/example-dih/solr/db/conf

Edit Mysql-data-config.xml to add new content as needed, see Db-data-config.xml file in the same directory

<dataConfig>
<datasource driver= "Com.mysql.jdbc.Driver" url= "Jdbc:mysql://localhost:3306/basic" user= "root" password= "123"/ >
<document>
<entity name= "article" transformer= "Htmlstriptransformer"
query= "SELECT ID, title, content from article" >
<field column= "id" name= "id"/>
<field column= "title" Name= "title"/>
<field column= "Content" name= "Content" striphtml= "true"/>
</entity>
</document>
</dataConfig>

Transformer= "Htmlstriptransformer" is used with striphtml= "true" to filter the body HTML tags.

Configuring DataImport Handler

Open SOLR Management background, select the appropriate core, select DataImport (see the second one below)
Initial use of this feature will show: Sorry, no Dataimport-handler defined!
Edit Solrconfig

[Email protected] ~]# VI solr-4.5.1/example/solr/collection1/conf/solrconfig.xml

Add the following code

<requesthandler name= "/dataimport" class= "Org.apache.solr.handler.dataimport.DataImportHandler" >
<lst name= "Defaults" >
<str name= "config" >/root/solr-4.5.1/example/example-DIH/solr/db/conf/mysql-data-config.xml</str>
</lst>
</requestHandler>

Add location according to their own habits, easy to find, I put it in the system built in the last handler,replication, such as:

Restart Error: Java.lang.ClassNotFoundException:org.apache.solr.handler.dataimport.DataImportHandler
Introduce the package you need to

[email protected] ~]# CP solr-4.5.1/dist/solr-dataimporthandler-*.jar/opt/tomcat/webapps/solr/web-inf/lib/

Because it involves connecting to MySQL, find a MySQL driver package and put it in the above Lib.

Restart

Execute CREATE INDEX

    1. Select the corresponding core;
    2. Select DataImport;
    3. Select entity article; (Note that the list of entities in Solr 4.9.0 is empty, workaround see: For security reasons, Solrresourceloader cannot load files from outside the Instan Ce ' s directory)
    4. Execute execute;
    5. Refresh status to view the status, and the right side will show the correct number of indexes.

If this content is helpful to you, welcome to click on the form of ads to support us, but please do not more than once a day, or may be identified as malicious click, resulting in the number.

SOLR dih Batch index for data source with MySQL

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.