Getting Started with SOLR: importing data

Source: Internet
Author: User
Tags sql server driver solr

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 "/&GT;&NBSP;&NBsp;  </entity>   </document> </dataconfig> 

Configure basic with MySQL and restart Tomcat.

Service Tomcat6 Restart


Getting Started with SOLR: importing data

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.