一. 搭建solr伺服器
1.下載solr http://archive.apache.org/dist/lucene/solr/5.4.1/ ,並解壓
2.將..\solr-5.4.1\example\example-DIH目錄下的solr檔案夾複製到tomcat根目錄下
3.將..\solr-5.4.1\server\solr-webapp目錄下的webapp複製到tomcat\webapp下並命名為為solr
4.將..\solr-5.4.1\server\lib\ext目錄下的所有jar包複製到..\apache-tomcat-7.0.67\webapps\solr\WEB-INF\lib下
5.將..\solr-5.4.1\dist目錄下的solr-dataimporthandler-5.4.1.jar和solr-dataimporthandler-extras-5.4.1.jar複製到..\apache-tomcat-7.0.67\webapps\solr\WEB-INF\lib下
6.將..\solr-5.4.1\server\resources目錄下的log4j.properties複製到..\apache-tomcat-7.0.67\webapps\solr\WEB-INF\classes下
如果沒有classes檔案,則建立一個
7.修改..\apache-tomcat-7.0.67\webapps\solr\WEB-INF目錄下的web.xml
找到<env-entry>節點,刪除注釋,修改如下 [html] view plain copy print ? <span style="white-space:pre"> </span> <env-entry> <env-entry-name>solr/home</env-entry-name> <!--指向tomcat根目錄下的solr檔案夾 --> <env-entry-value>E:\apache-tomcat-7.0.67\solr</env-entry-value> <env-entry-type>java.lang.String</env-entry-type> </env-entry>
8.啟動tomcat,訪問 http://localhost:8080/solr/index.html#/, 出現如下頁面說明搭建成功
二. 串連資料庫
1.SQL配置
以MySQL為例,需要下載mysql-connector-Java-bin.jar到..\apache-tomcat-7.0.67\webapps\solr\WEB-INF\lib目錄下
http://dev.mysql.com/downloads/file/?id=462849
2.建立查詢
進入在solr/home 目錄下也就是本例的..\apache-tomcat-7.0.67\solr目錄下
複製db得到collection
進入..\apache-tomcat-7.0.67\solr\collection目錄下,編輯conf檔案夾下的db-data-config.xml檔案 [html] view plain copy print ? <dataConfig> <dataSourcedriverdataSourcedriver="com.mysql.jdbc.Driver"url="jdbc:mysql://localhost:3306/dubbotest?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull"user="root" password="123456" /> <document> <entity name="Student" query="select* from t_student" deltaQuery="select * fromt_student where last_modified > '${dataimporter.last_index_time}'" deltaImportQuery="SELECT* FROM t_student where last_modified >'${dataimporter.last_index_time}'"> <field column="id"name="id" /> <fieldcolumnfieldcolumn="name" name="name" /> <fieldcolumnfieldcolumn="sex"