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
- Select the corresponding core;
- Select DataImport;
- 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)
- Execute execute;
- 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