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 Configuring Solr to Use MySQL
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
Solr can be configured to connect to a MySQL Data base using the DataImportHandler. To do so first in
solrconfig.xml
(This file would be in
Solr Dir/example/conf
) add a new requestHandler which is handled by DIH (DataImportHandler).
<span><span><requesthandler> <span>name</span> =<span>"/dataimport"</span> </requesthandler></span> <br> <span> <span>class</span> =<span>"org.apache.solr.handler.dataimport.DataImportHandler"</span> <span>></span> </span> <br> <span><span><lst> <span>name</span> =<span>"defaults"</span> <span>></span> </lst></span> <br> <span><span><str> <span>name</span> =<span>"config"</span> <span>></span> </str></span> data-config.xml<span><span><span>></span> </span> </span> <br> <span><span><span>></span> </span> </span> <br> <span><span><span>><br> <br> </span> </span> </span> </span></span></span>
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
<span><span><dataconfig>></dataconfig></span> </span> <br> <span><span><datasource> <span>type</span> =<span>"JdbcDataSource"</span> </datasource></span> <br> <span> <span>driver</span> =<span>"com.mysql.jdbc.Driver"</span> </span> <br> <span> <span>url</span> =<span>"jdbc:mysql://SERVER/DATABASE"</span> </span> <br> <span> <span>user</span> =<span>"USERNAME"</span> </span> <br> <span> <span>password</span> =<span>"PASSWORD"</span> <span>/></span> </span> <br> <span><span><document> <span>name</span> =<span>"content"</span> <span>></span> </document></span> <br> <span><span><entity> <span>name</span> =<span>"node"</span> <span>query</span> =<span>"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"</span> <span>></span> </entity></span> <br> <span><span><field> <span>column</span> =<span>"nid"</span> <span>name</span> =<span>"id"</span> <span>/></span> </field></span> <br> <span><span><field> <span>column</span> =<span>"body"</span> <span>name</span> =<span>"body"</span> <span>/></span> </field></span> <br> <span><span><field> <span>column</span> =<span>"title"</span> <span>name</span> =<span>"title"</span> <span>/></span> </field></span> <br> <span><span><span>></span> </span> </span> <br> <span><span><span>></span> </span> </span> <br> <span><span><span>><br> </span> </span> </span> </span></span></span></span></span></span>
The dataSource configuration attributes , query in entity tag and database fields must be modified to match your database structure. The Query given in the example is a simple Join of the drupal node and node revisions tables.
Now restart or start ApacheSolr using java -jar start.jar .
Hit the full-commit url (http://SERVER:PORT/solr/dataimport?command=full-import) and your website would start getting indexed.
<span><span><response>></response></span> </span> <br> <br> <span><span><lst> <span>name</span> =<span>"responseHeader"</span> <span>></span> </lst></span> <br> <span><span><int> <span>name</span> =<span>"status"</span> <span>></span> </int></span> 0<span><span><span>></span> </span> </span> <br> <span><span><int> <span>name</span> =<span>"QTime"</span> <span>></span> </int></span> 0<span><span><span>></span> </span> </span> <br> <span><span><span>></span> </span> </span> <br> <br> <span><span><lst> <span>name</span> =<span>"initArgs"</span> <span>></span> </lst></span> <br> <br> <span><span><lst> <span>name</span> =<span>"defaults"</span> <span>></span> </lst></span> <br> <span><span><str> <span>name</span> =<span>"config"</span> <span>></span> </str></span> data-config.xml<span><span><span>></span> </span> </span> <br> <span><span><span>></span> </span> </span> <br> <span><span><span>></span> </span> </span> <br> <span><span><str> <span>name</span> =<span>"command"</span> <span>></span> </str></span> full-import<span><span><span>></span> </span> </span> <br> <span><span><str> <span>name</span> =<span>"status"</span> <span>></span> </str></span> idle<span><span><span>></span> </span> </span> <br> <span><span><str> <span>name</span> =<span>"importResponse"</span> <span>/></span> </str></span> <br> <br> <span><span><lst> <span>name</span> =<span>"statusMessages"</span> <span>></span> </lst></span> <br> <span><span><str> <span>name</span> =<span>"Total Requests made to DataSource"</span> <span>></span> </str></span> 1<span><span><span>></span> </span> </span> <br> <span><span><str> <span>name</span> =<span>"Total Rows Fetched"</span> <span>></span> </str></span> 1056<span><span><span>></span> </span> </span> <br> <span><span><str> <span>name</span> =<span>"Total Documents Skipped"</span> <span>></span> </str></span> 0<span><span><span>></span> </span> </span> <br> <span><span><str> <span>name</span> =<span>"Full Dump Started"</span> <span>></span> </str></span> 2010-02-22 14:46:35<span><span><span>></span> </span> </span> <br> <br> <span><span><str> <span>name</span> =<span>""</span> <span>></span> </str></span> <br> Indexing completed. Added/Updated: 1056 documents. Deleted 0 documents.<br> <span><span><span>></span> </span> </span> <br> <span><span><str> <span>name</span> =<span>"Committed"</span> <span>></span> </str></span> 2010-02-22 14:46:42<span><span><span>></span> </span> </span> <br> <span><span><str> <span>name</span> =<span>"Optimized"</span> <span>></span> </str></span> 2010-02-22 14:46:42<span><span><span>></span> </span> </span> <br> <span><span><str> <span>name</span> =<span>"Total Documents Processed"</span> <span>></span> </str></span> 1056<span><span><span>></span> </span> </span> <br> <span><span><str> <span>name</span> =<span>"Time taken "</span> <span>></span> </str></span> 0:0:6.562<span><span><span>></span> </span> </span> <br> <span><span><span>></span> </span> </span> <br> <br> <span><span><str> <span>name</span> =<span>"WARNING"</span> <span>></span> </str></span> <br> This response format is experimental. It is likely to change in the future.<br> <span><span><span>></span> </span> </span> <br> <span><span><span>></span> </span> </span> </span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>