<blockquote><h4>認(rèn)識(shí)Solr</h4></blockquote>
??????Solr是一個(gè)高性能,采用Java5開發(fā)Solr基于Lucene的全文搜索服務(wù)器。同時(shí)對(duì)其進(jìn)行了擴(kuò)展,提供了比Lucene更為豐富的查詢語言,同時(shí)實(shí)現(xiàn)了可配置、可擴(kuò)展并對(duì)查詢性能進(jìn)行了優(yōu)化,并且提供了一個(gè)完善的功能管理界面,是一款非常優(yōu)秀的全文搜索引擎。,
<blockquote><h4>Solr工作方式</blockquote>
??????文檔通過Http利用XML 加到一個(gè)搜索集合中。Solr查詢?cè)摷弦彩峭ㄟ^http收到一個(gè)XML/JSON響應(yīng)來實(shí)現(xiàn)。它的主要特性包括:高效、靈活的緩存功能,垂直搜索功能,高亮顯示搜索結(jié)果,通過索引復(fù)制來提高可用性,提供一套強(qiáng)大Data Schema來定義字段,類型和設(shè)置文本分析,提供基于Web的管理界面等。
<blockquote><h4>Solr4-MySQL集成搭建</blockquote>
*準(zhǔn)備
???1.1下載solr http://mirrors.hust.edu.cn/apache/lucene/solr/
???1.2解壓solr-4.10.4,進(jìn)入dist目錄

???1.3將solr-4.10.4.war復(fù)制到tomcat中的webapps下,啟動(dòng)tomcat,war包自動(dòng)解壓
???1.4修改solr下的web.xml,在web-app中添加
<env-entry>
<env-entry-name>solr/home</env-entry-name>
<env-entry-value>D:\solrhome</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
???1.5在D盤創(chuàng)建solrhome文件夾(根據(jù)個(gè)人需求)
???1.6回到解壓的solr-4.10.4目錄,打開文件夾:solr-4.10.0\example\solr,復(fù)制所有內(nèi)容到D:\solrhome
???1.7打開文件夾:solr-4.10.0\example\lib\ext,復(fù)制所有jar包到tomcat的webapps\solr\WEB-INF\lib下。
???1.8啟動(dòng)tomcat

???1.9在D:\solrhome目錄下,新建一個(gè)user文件夾。
???1.10在解壓的solr-4.10.4\example\multicore\core0目錄中,復(fù)制conf文件夾到D:\solrhome\user中。
???1.11在solr web page中新建core:

???1.12創(chuàng)建完成之后下載mysql驅(qū)動(dòng)包http://dev.mysql.com/downloads/connector/j/
???1.13將solr-4.10.4/dist下的solr-dataimporthandler-4.10.4.jar、solr-dataimporthandler-extras-4.10.4.jar和mysql-connector-java-5.1.18-bin.jar拷貝到webapps\solr\WEB-INF\lib下
1.14修改D:\solrhome\user\conf下的solrconfig.xml,追加
<requestHandler name="/dataimport"
class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">data-config.xml</str>
</lst>
</requestHandler>
1.15在同一目錄下創(chuàng)建data-config.xml
<dataConfig>
<dataSource type="JdbcDataSource"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://127.0.0.1:3306/zhangxp"
user="root"
password="123456"/>
<document name="search_object">
<entity name="user"
query="select id, username, age
from user">
</entity>
</document>
</dataConfig>
1.16因?yàn)樵趕chema.xml中沒有配置username、age的filed屬性,所以需要手動(dòng)配置
<!--用戶表-->
<field name="username" type="string" indexed="true" stored="true" multiValued="false" />
<field name="age" type="string" indexed="true" stored="true" multiValued="false" />
1.17以上配置成功之后,啟動(dòng)服務(wù)

1.18點(diǎn)擊execute執(zhí)行命令導(dǎo)入數(shù)據(jù)
1.19點(diǎn)擊Query查看數(shù)據(jù)是否導(dǎo)入成功


