One, connect MySQL
MySQL Java Connector, downloaded and placed in the SOLR Runtime library.
cp/tmp/mysql-connector-java-5.1.30.jar/usr/share/tomcat6/webapps/solr/web-inf/lib/
Open and edit the SOLR configuration file {Solr/home}:
Vim/home/solr-index/collection1/conf/solrconfig.xml
Add the following (recommended to be added in the RequestHandler area, easy to manage.) ):
<requesthandler name= "/dataimport" class= "Org.apache.solr.handler.dataimport.DataImportHandler" > <lst Name= "Defaults" > <str name= "config" >data-config.xml</str> </lst></requestHandler>
Creates a new Data-config.xml file that is named as a file that is added in the preceding configuration file .
Vim/home/solr-index/collection1/conf/data-config.xml
Write the configuration content in Data-config.xml:
<?xml version= "1.0" encoding= "Utf-8"?><dataconfig> <datasource Type= "Jdbcdatasource" driver= "Com.mysql.jdbc.Driver" url= "Jdbc:mysql://localhost:3306/db_example" user= "Root" password= "123456"/> < Document name= "Search" > <entity name= "view_table" pk= "id" query= "Select * from s_table" > <field column= "id" name= "id"/> <field column= "title" Name= "title"/> <field column= "Content" name= "content"/> </entity> </document> </dataConfig>
In the above configuration file, DataSource is required for a database connection where the URL is the database address and Db_example is the name of the database opened for the current connection. The user and password correspond to the account number and password of the connection database respectively. The SQL query statement that is executed in entity for importing data allows you to simultaneously create multiple fields that are Entity,field for the query, or you can create multiple bars as needed.
Restart Tomcat
Service Tomcat6 Restart
Second, connect SQL Server
Similarly, download the SQL Server Driver engine, because JDBC compatibility is more tangled, in order to compatible with SQL Server2000 so choose Jtds. After the download, the jar file is placed in the SOLR Runtime Library.
cp/tmp/jtds-1.3.1.jar/usr/share/tomcat6/webapps/solr/web-inf/lib/
Open and edit the SOLR configuration file {Solr/home}:
Vim/home/solr-index/collection2/conf/solrconfig.xml
Write the configuration content in Data-config.xml:
<?xml version= "1.0" encoding= "Utf-8"?><dataconfig> <datasource Type= "Jdbcdatasource" driver= "Net.sourceforge.jtds.jdbc.Driver" url= "Jdbc:jtds:sqlserver://127.0.0.1:1433/db_example2" user= "Root" password= "123456"/> <document name= "Search" > <entity name= "View_ Table " pk=" id " query=" select * from s_table "> <field column= "id" name= "id"/> <field column= "title" name= "title"/> <field column= "Content" name= " Content "/>&NBSP;&NBsp; </entity> </document> </dataconfig>
Configure basic with MySQL and restart Tomcat.
Service Tomcat6 Restart
Getting Started with SOLR: importing data