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
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
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).
name = "/dataimport"
class = "org.apache.solr.handler.dataimport.DataImportHandler" >
name = "defaults" >
name = "config" > data-config.xml >
>
>
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
>
type = "JdbcDataSource"
driver = "com.mysql.jdbc.Driver"
url = "jdbc:mysql://SERVER/DATABASE"
user = "USERNAME"
password = "PASSWORD" />
name = "content" >
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" >
column = "nid" name = "id" />
column = "body" name = "body" />
column = "title" name = "title" />
>
>
>
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.
>
name = "responseHeader" >
name = "status" > 0 >
name = "QTime" > 0 >
>
name = "initArgs" >
name = "defaults" >
name = "config" > data-config.xml >
>
>
name = "command" > full-import >
name = "status" > idle >
name = "importResponse" />
name = "statusMessages" >
name = "Total Requests made to DataSource" > 1 >
name = "Total Rows Fetched" > 1056 >
name = "Total Documents Skipped" > 0 >
name = "Full Dump Started" > 2010-02-22 14:46:35 >
name = "" >
Indexing completed. Added/Updated: 1056 documents. Deleted 0 documents.
>
name = "Committed" > 2010-02-22 14:46:42 >
name = "Optimized" > 2010-02-22 14:46:42 >
name = "Total Documents Processed" > 1056 >
name = "Time taken " > 0:0:6.562 >
>
name = "WARNING" >
This response format is experimental. It is likely to change in the future.
>
>
查看更多关于solr索引mysqlDIH链接的详细内容...