Solr使用入門指南_第1頁
Solr使用入門指南_第2頁
Solr使用入門指南_第3頁
Solr使用入門指南_第4頁
Solr使用入門指南_第5頁
已閱讀5頁,還剩21頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

Solr使用入門指南由于搜索引擎功能在門戶小區(qū)中對提高顧客體驗有著重在門戶小區(qū)中波及大量需要搜索引擎的功能需求,目前在實現(xiàn)搜索引擎的方案上有集中方案可供選擇:1.基于Lucene自己進行封裝實現(xiàn)站內(nèi)搜索。工作量及擴展性都較大,不采用。2.調(diào)用Google、百度的API實現(xiàn)站內(nèi)搜索。同第三方搜索引擎綁定太死,無法滿足后期業(yè)務(wù)擴展需要,臨時不采用。3.基于Compass+Lucene實現(xiàn)站內(nèi)搜索。適合于對數(shù)據(jù)庫驅(qū)動的應(yīng)用數(shù)據(jù)進行索引,尤其是替代老式的like‘%expression%’來實現(xiàn)對varchar或clob等字段的索引,對于實現(xiàn)站內(nèi)搜索是一種值得采納的方案。但在分布式處理、接口封裝上尚需要自己進行一定程度的封裝,臨時不采用。4.基于Solr實現(xiàn)站內(nèi)搜索。封裝及擴展性很好,提供了較為完備的處理方案,因此在門戶小區(qū)中采用此方案,后期加入Compass方案。1、Solr簡介Solr是一種基于Lucene的Java搜索引擎服務(wù)器。Solr提供了層面搜索、命中醒目顯示并且支持多種輸出格式(包括XML/XSLT和JSON格式)。它易于安裝和配置,并且附帶了一種基于HTTP的管理界面。Solr已經(jīng)在眾多大型的網(wǎng)站中使用,較為成熟和穩(wěn)定。Solr包裝并擴展了Lucene,因此Solr的基本上沿用了Lucene的有關(guān)術(shù)語。更重要的是,Solr創(chuàng)立的索引與Lucene搜索引擎庫完全兼容。通過對Solr進行合適的配置,某些狀況下也許需要進行編碼,Solr可以閱讀和使用構(gòu)建到其他Lucene應(yīng)用程序中的索引。此外,諸多Lucene工具(如Nutch、Luke)也可以使用Solr創(chuàng)立的索引。2、Tomcat下Solr安裝配置由于Solr基于java開發(fā),因此Solr在windows及Linux都能很好布署使用,但由于Solr提供了某些用于測試及管理、維護較為以便的shell腳本,因此在生產(chǎn)布署時候提議安裝在Linux上,測試時候可以在windows使用。下面以Linux下安裝配置Solr進行闡明,windows與此類似。wgetunzipapache-tomcat-6.0.16.zipmvapache-tomcat-6.0.16/opt/tomcatchmod755/opt/tomcat/bin/*wgettarzxvfapache-solr-1.2.0.tgzSolr的安裝配置最為麻煩的是對solr.solr.home的理解和配置,重要有三種基于目前途徑的方式cpapache-solr-1.2.0/dist/apache-solr-1.2.0.war/opt/tomcat/webapps/solr.warmkdir/opt/solr-tomcatcp-rapache-solr-1.2.0/example/solr//opt/solr-tomcat/cd/opt/solr-tomcat/opt/tomcat/bin/startup.sh由于在此種狀況下(沒有設(shè)定solr.solr.home環(huán)境變量或JNDI的狀況下),Solr查找./solr,因此在啟動時候需要切換到/opt/solr-tomcat基于環(huán)境變量solr.solr.home在目前顧客的環(huán)境變量中(.bash_profile)或在/opt/tomcat/catalina.sh中添加如下環(huán)境變量exportJAVA_OPTS="$JAVA_OPTS-Dsolr.solr.home=/opt/solr-tomcat/solr"基于JNDI配置mkdir–p/opt/tomcat/conf/Catalina/localhosttouch/opt/tomcat/conf/Catalina/localhost/solr.xml,內(nèi)容如下:Xml代碼<Context

docBase="/opt/tomcat/webapps/solr.war"

debug="0"

crossContext="true"

>

<Environment

name="solr/home"

type="java.lang.String"

value="/opt/solr-tomcat/solr"

override="true"

/>

</Context>

訪問solr管理界面http://ip:port/solr3、Solr原理Solr對外提供原則的http接口來實現(xiàn)對數(shù)據(jù)的索引的增長、刪除、修改、查詢。在Solr中,顧客通過向布署在servlet容器中的SolrWeb應(yīng)用程序發(fā)送HTTP祈求來啟動索引和搜索。Solr接受祈求,確定要使用的合適SolrRequestHandler,然后處理祈求。通過HTTP以同樣的方式返回響應(yīng)。默認配置返回Solr的原則XML響應(yīng),也可以配置Solr的備用響應(yīng)格式??梢韵騍olr索引servlet傳遞四個不一樣的索引祈求:add/update容許向Solr添加文檔或更新文檔。直到提交后才能搜索到這些添加和更新。commit告訴Solr,應(yīng)當使上次提交以來所做的所有更改都可以搜索到。optimize重構(gòu)Lucene的文獻以改善搜索性能。索引完畢后執(zhí)行一下優(yōu)化一般比很好。假如更新比較頻繁,則應(yīng)當在使用率較低的時候安排優(yōu)化。一種索引無需優(yōu)化也可以正常地運行。優(yōu)化是一種耗時較多的過程。delete可以通過id或查詢來指定。按id刪除將刪除具有指定id的文檔;按查詢刪除將刪除查詢返回的所有文檔。一種經(jīng)典的Add祈求報文Xml代碼<add>

<doc>

<field

name="id">TWINX2048-3200PRO</field>

<field

name="name">CORSAIR

XMS

2GB

(2

x

1GB)

184-Pin

DDR

SDRAM

Unbuffered

DDR

400

(PC

3200)

Dual

Channel

Kit

System

Memory

-

Retail</field>

<field

name="manu">Corsair

Microsystems

Inc.</field>

<field

name="cat">electronics</field>

<field

name="cat">memory</field>

<field

name="features">CAS

latency

2,

2-3-3-6

timing,

2.75v,

unbuffered,

heat-spreader</field>

<field

name="price">185</field>

<field

name="popularity">5</field>

<field

name="inStock">true</field>

</doc>

<doc>

<field

name="id">VS1GB400C3</field>

<field

name="name">CORSAIR

ValueSelect

1GB

184-Pin

DDR

SDRAM

Unbuffered

DDR

400

(PC

3200)

System

Memory

-

Retail</field>

<field

name="manu">Corsair

Microsystems

Inc.</field>

<field

name="cat">electronics</field>

<field

name="cat">memory</field>

<field

name="price">74.99</field>

<field

name="popularity">7</field>

<field

name="inStock">true</field>

</doc>

</add>

一種經(jīng)典的搜索成果報文:Xml代碼<response>

<lst

name="responseHeader">

<int

name="status">0</int>

<int

name="QTime">6</int>

<lst

name="params">

<str

name="rows">10</str>

<str

name="start">0</str>

<str

name="fl">*,score</str>

<str

name="hl">true</str>

<str

name="q">content:"faceted

browsing"</str>

</lst>

</lst>

<result

name="response"

numFound="1"

start="0"

maxScore="1.058217">

<doc>

<float

name="score">1.058217</float>

<arr

name="all">

<str>http://localhost/myBlog/solr-rocks-again.html</str>

<str>Solr

is

Great</str>

<str>solr,lucene,enterprise,search,greatness</str>

<str>Solr

has

some

really

great

features,

like

faceted

browsing

and

replication</str>

</arr>

<arr

name="content">

<str>Solr

has

some

really

great

features,

like

faceted

browsing

and

replication</str>

</arr>

<date

name="creationDate">-01-07T05:04:00.000Z</date>

<arr

name="keywords">

<str>solr,lucene,enterprise,search,greatness</str>

</arr>

<int

name="rating">8</int>

<str

name="title">Solr

is

Great</str>

<str

name="url">http://localhost/myBlog/solr-rocks-again.html</str>

</doc>

</result>

<lst

name="highlighting">

<lst

name="http://localhost/myBlog/solr-rocks-again.html">

<arr

name="content">

<str>Solr

has

some

really

great

features,

like

<em>faceted</em>

<em>browsing</em>

and

replication</str>

</arr>

</lst>

</lst>

</response>

有關(guān)solr的詳細使用闡明,請參照4、Solr測試使用Solr的安裝包包括了有關(guān)的測試樣例,途徑在apache-solr-1.2.0/example/exampledocs1.使用shell腳本(curl)測試Solr的操作:cdapache-solr-1.2.0/example/exampledocsvipost.sh,根據(jù)tomcat的ip、port修改URL變量的值URL=http://localhost:8080/solr/update./post.sh*.xml

#2.使用Solr的java包測試Solr的操作:查看協(xié)助:java-jarpost.jar–help提交測試數(shù)據(jù):java-Durl=http://localhost:8080/solr/update-Ddata=files-jarpost.jar

*.xml

下面以增長索引字段liangchuan、url為例,闡明一下Solr中索引命令的使用1)修改solr的schema,配置需要索引字段的闡明:vi/opt/solr-tomcat/solr/conf/schema.xml,在<fields>中增長如下內(nèi)容Xml代碼<field

name="liangchuan"

type="string"

indexed="true"

stored="true"/>

<field

name="url"

type="string"

indexed="true"

stored="true"/>

[xml]\o"viewplain"viewplain\o"copy"copy<field

name="liangchuan"

type="string"

indexed="true"

stored="true"/>

<field

name="url"

type="string"

indexed="true"

stored="true"/>

2)創(chuàng)立增長索引祈求的xml測試文獻touch/root/apache-solr-1.2.0/example/exampledocs/liangchuan.xml,內(nèi)容如下:Xml代碼<add>

<doc>

<field

name="id">liangchuan000</field>

<field

name="name">Solr,

the

Enterprise

Search

Server</field>

<field

name="manu">Apache

Software

Foundation</field>

<field

name="liangchuan">liangchuan's

solr

"hello,world"

test</field>

<field

name="url"></field>

</doc>

</add>

3)提交索引祈求cdapache-solr-1.2.0/example/exampledocs./post.shliangchuan.xml4)查詢通過solr的管理員界面http://localhost:8080/solr/admin查詢或通過curl測試:exportURL="http://localhost:8080/solr/select/"curl"$URL?indent=on&q=liangchuan&fl=*,score"5、Solr查詢條件參數(shù)闡明參數(shù)

描述

示例q

Solr中用來搜索的查詢??梢酝ㄟ^追加一種分號和已索引且未進行斷詞的字段的名稱來包括排序信息。默認的排序是scoredesc,指按記分降序排序。

q=myField:JavaANDotherField:developerWorks;dateasc此查詢搜索指定的兩個字段并根據(jù)一種日期字段對成果進行排序。start

將初始偏移量指定到成果集中??捎糜趯Τ晒M行分頁。默認值為0。

start=15返回從第15個成果開始的成果。rows

返回文檔的最大數(shù)目。默認值為10。

rows=25f

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論