什麼是Solrjava
solr是Apache下的一個頂級開源項目,採用java開發,它基於Lucene的全文搜索服務器。solr提供了比Lucene更爲豐富的查詢語言,同時實現了可配置,可拓展,並對索引,搜索性能進行了優化。mysql
solr能夠獨立運行,運行在Jetty,Tomcat等這些Servlet容器中,Solr索引實現方法很簡單,用post方法向服務器發送一個描述Field及其內容的XML文檔,Solr根據xml文檔添加,刪除,跟新索引,solr搜索只須要發送HTTP GET請求,而後對solr返回XML,JSON等格式的查詢結果進行解析,組織頁面佈局。sorl不提供構建UI的功能,solr提供了一個管理界面,經過管理界面能夠查詢solr的配置和運行狀況。web
solr和Lucene的區別:sql
Lucene是一個開源的全文檢索引擎工具包,它不是一個完整的全文檢索引擎,Lucene提供了完整的查詢引擎和索引引擎,目的是爲軟件開發人員提供一個簡單易用的工具包,以方便的在目標系統中實現全文檢索的功能,或以Lucene爲基礎構建全文檢索引擎。數據庫
solr的目標是打造一款企業級的搜索引擎系統,它是一個搜索引擎服務,能夠獨立運行,經過solr能夠很是快速的構建企業的搜索引擎,經過solr也能夠高效的完成站內搜索功能。apache
從Solr官方網站(http://lucene.apache.org/solr/ )下載Solr4.10.3,根據Solr的運行環境,Linux下須要下載lucene-4.10.3.tgz,windows下須要下載lucene-4.10.3.zip。windows
Solr使用指南可參考:https://wiki.apache.org/solr/FrontPage。tomcat
bin:solr的運行腳本服務器
contrib:solr的一些貢獻軟件/插件,用於加強solr的功能。app
dist:該目錄包含build過程當中產生的war和jar文件,以及相關的依賴文件。
docs:solr的API文檔
example:solr工程的例子目錄:
l example/solr:
該目錄是一個包含了默認配置信息的Solr的Core目錄。
l example/multicore:
該目錄包含了在Solr的multicore中設置的多個Core目錄。
l example/webapps:
該目錄中包括一個solr.war,該war可做爲solr的運行實例工程。
licenses:solr相關的一些許可信息
使用tomcat做爲servlet容器,Solr4.10.3要求jdk使用1.7以上,Solr默認提供Jetty(java寫的Servlet容器)。
1---解壓tomcat,solr,建立solrhome文件夾。
2--把solr的war包複製到tomcat 的webapp目錄下。把\solr-4.10.3\dist\solr-4.10.3.war 複製到F:\apache-tomcat-7.0.53\webapps下。更名爲solr.war,解壓
或\solr-4.10.3\example\webapps位置也可 複製到F:\apache-tomcat-7.0.53\webapps下。解壓。
注:解壓以後刪除solr.war壓縮包
3--把\solr-4.10.3\example\lib\ext目錄下的全部的jar包添加到solr工程中
4--把第一步建立的solrhome(存放solr全部配置文件的一個文件夾)路徑複製到solr工程的web.xml裏。
5--\solr-4.10.3\example\solr目錄就是一個標準的solrhome。(將其目錄裏全部文件拷貝到咱們創建的solrhome裏)
6--啓動tomcat訪問http://localhost:8080/solr/ 成功以下
****************************************************************************************************
*************************************************************************************
<!-- IKAnalyzer--> <fieldType name="text_ik" class="solr.TextField"> <analyzer class="org.wltea.analyzer.lucene.IKAnalyzer"/> </fieldType> <!--IKAnalyzer Field--> <field name="title_ik" type="text_ik" indexed="true" stored="true" /> <field name="content_ik" type="text_ik" indexed="true" stored="false" multiValued="true"/>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>IK Analyzer 擴展配置</comment>
<!--用戶能夠在這裏配置本身的擴展字典
-->
<entry key="ext_dict">ext.dic;</entry>
<!--用戶能夠在這裏配置本身的擴展中止詞字典-->
<entry key="ext_stopwords">stopword.dic;</entry>
</properties>
我 是 a an and are as at be but by for if in into is it no not of on or such that the their then there these they this to was will with
高富帥
白富美
中國人
注意:若是id相同那麼就是修改(底層是先刪除在添加)
<requestHandler name="/dataimport"
class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">data-config.xml</str>
</lst>
</requestHandler>
<?xml version="1.0" encoding="UTF-8" ?> <dataConfig> <dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/lucene" <!--注意修改數據庫--> user="root" password="root"/> <document> <!--查詢映射--> <entity name="product" query="SELECT pid,name,catalog_name,price,description,picture FROM products "> <field column="pid" name="id"/> <field column="name" name="product_name"/> <field column="catalog_name" name="product_catalog_name"/> <field column="price" name="product_price"/> <field column="description" name="product_description"/> <field column="picture" name="product_picture"/> </entity> </document> </dataConfig>
注意schema.xml裏面沒有相關域的配置,故須要添加
<!--product--> <field name="product_name" type="text_ik" indexed="true" stored="true"/> <field name="product_price" type="float" indexed="true" stored="true"/> <field name="product_description" type="text_ik" indexed="true" stored="false" /> <field name="product_picture" type="string" indexed="false" stored="true" /> <field name="product_catalog_name" type="string" indexed="true" stored="true" /> <!--拷貝域,名字和描述都拷貝到keywords裏--> <field name="product_keywords" type="text_ik" indexed="true" stored="false" multiValued="true"/> <copyField source="product_name" dest="product_keywords"/> <copyField source="product_description" dest="product_keywords"/>
大括號表示不包含,中括號表示包含