Solr连接MYSQL导入源数据生成索引

1.在需要导入的索引目录(core)下的conf/solrconfig.xml配置
比如:C:\solr-tomcat\solr\core2\conf\solrconfig.xml
   <lib dir="D:/vm/Hadoop/Hadoop_Setup/apache-solr-3.6.1/apache-solr-3.6.1/contrib/extraction/lib" />
    <lib dir="D:/vm/Hadoop/Hadoop_Setup/apache-solr-3.6.1/apache-solr-3.6.1/dist/" regex="apache-solr-cell-\d.*\.jar" />
    <lib dir="D:/vm/Hadoop/Hadoop_Setup/apache-solr-3.6.1/apache-solr-3.6.1/dist/" regex="apache-solr-clustering-\d.*\.jar" />
    <lib dir="D:/vm/Hadoop/Hadoop_Setup/apache-solr-3.6.1/apache-solr-3.6.1/dist/" regex="apache-solr-dataimporthandler-\d.*\.jar" />
    <lib dir="D:/vm/Hadoop/Hadoop_Setup/apache-solr-3.6.1/apache-solr-3.6.1/contrib/clustering/lib/" />
    <lib dir="/total/crap/dir/ignored" />
 <requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
        <lst name="defaults">
            <str name="config">data-config.xml</str>
        </lst>
    </requestHandler>
2.编写data-config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<dataConfig>
<dataSource type="JdbcDataSource"  driver="com.mysql.jdbc.Driver" url="jdbc:mysql://192.168.1.253/mc" user="root" password=""/>
   <document name="content">
       <entity name="node" query="select productionid,specification from tproductionbewrite limit 8">
           <field column="productionid" name="productionid" />
           <field column="specification" name="specification" />         
        </entity>
    </document>
</dataConfig>
3.在C:\solr-tomcat\solr\core2\目录创建lib目录,导入mysql-connector-java-5.1.21-bin.jar包即可
4.启动tomcat,访问Solr服务器
5.http://localhost:8080/solr/core2/dataimport?command=full-import ;  ---即可从MYSQL导入数据建立索引
posted @ 2012-10-07 22:36  bobsoft  阅读(266)  评论(0编辑  收藏  举报