Download the JDBC driver
Download the JDBC driver for MySQL from http://mysql.spd.co.il/Downloads/Connector-J/mysql-connector-java-3.1.14.zip
Put the "mysql-connector-java-3.1.14-bin.jar" in
Solr Dir/example/lib
Using ing SOLR to use MySQL
SOLR can be configured to connect to a MySQL data base using
Dataimporthandler. To do so first in
solrconfig.xml
(This file wocould be in
Solr Dir/example/conf
) Add a new requesthandler which is
Handled by DIH (dataimporthandler ).
<requestHandler name="/dataimport"
class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">data-config.xml</str>
</lst>
</requestHandler>
Create a new file called data-config.xml in the same directory and
Configure the database connection and table schema to reflect your
Database structure.
Sample data-config.xml
<dataConfig>
<dataSource type="JdbcDataSource"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://SERVER/DATABASE"
user="USERNAME"
password="PASSWORD"/>
<document name="content">
<entity name="node" query="select node.nid AS nid,node_revisions.body AS body,node_revisions.title AS title from node,node_revisions where node.status = 1 and node.nid = node_revisions.nid and node.vid = node_revisions.vid">
<field column="nid" name="id" />
<field column="body" name="body" />
<field column="title" name="title" />
</entity>
</document>
</dataConfig>
The datasource configuration attributes, query in Entity tag and
Database fields must be modified to match your database structure.
Query given in the example is a simple join of the Drupal node and Node
Revisions tables.
Now restart or start apachesolr usingJava-jar start. Jar
.
Hit the full-commit URL
(Http: // server: Port/SOLR/dataimport? Command = Full-import) and your
Website wocould start getting indexed.
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">0</int>
</lst>
<lst name="initArgs">
<lst name="defaults">
<str name="config">data-config.xml</str>
</lst>
</lst>
<str name="command">full-import</str>
<str name="status">idle</str>
<str name="importResponse"/>
<lst name="statusMessages">
<str name="Total Requests made to DataSource">1</str>
<str name="Total Rows Fetched">1056</str>
<str name="Total Documents Skipped">0</str>
<str name="Full Dump Started">2010-02-22 14:46:35</str>
<str name="">
Indexing completed. Added/Updated: 1056 documents. Deleted 0 documents.
</str>
<str name="Committed">2010-02-22 14:46:42</str>
<str name="Optimized">2010-02-22 14:46:42</str>
<str name="Total Documents Processed">1056</str>
<str name="Time taken ">0:0:6.562</str>
</lst>
<str name="WARNING">
This response format is experimental. It is likely to change in the future.
</str>
</response>