欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
Solr使用入門(mén)指南

 

本文轉自 http://chuanliang2007.spaces.live.com/blog/cns!E5B7AB2851A4C9D2!499.entry?wa=wsignin1.0

 

由于搜索引擎功能在門(mén)戶(hù)社區中對提高用戶(hù)體驗有著(zhù)重在門(mén)戶(hù)社區中涉及大量需要搜索引擎的功能需求,目前在實(shí)現搜索引擎的方案上有集中方案可供選擇:

1. 基于Lucene自己進(jìn)行封裝實(shí)現站內搜索。工作量及擴展性都較大,不采用。

2. 調用Google、Baidu的API實(shí)現站內搜索。同第三方搜索引擎綁定太死,無(wú)法滿(mǎn)足后期業(yè)務(wù)擴展需要,暫時(shí)不采用。

3. 基于Compass+Lucene實(shí)現站內搜索。適合于對數據庫驅動(dòng)的應用數據進(jìn)行索引,尤其是替代傳統的like ‘%expression%’來(lái)實(shí)現對varchar或clob等字段的索引,對于實(shí)現站內搜索是一種值得采納的方案。但在分布式處理、接口封裝上尚需要自己進(jìn)行一定程度的封裝,暫時(shí)不采用。

4. 基于Solr實(shí)現站內搜索。封裝及擴展性較好,提供了較為完備的解決方案,因此在門(mén)戶(hù)社區中采用此方案,后期加入Compass方案。

 

1、 Solr簡(jiǎn)介

Solr是一個(gè)基于Lucene的Java搜索引擎服務(wù)器。Solr 提供了層面搜索、命中醒目顯示并且支持多種輸出格式(包括 XML/XSLT 和 JSON 格式)。它易于安裝和配置,而且附帶了一個(gè)基于 HTTP 的管理界面。Solr已經(jīng)在眾多大型的網(wǎng)站中使用,較為成熟和穩定。Solr 包裝并擴展了 Lucene,所以Solr的基本上沿用了Lucene的相關(guān)術(shù)語(yǔ)。更重要的是,Solr 創(chuàng )建的索引與 Lucene 搜索引擎庫完全兼容。通過(guò)對Solr 進(jìn)行適當的配置,某些情況下可能需要進(jìn)行編碼,Solr 可以閱讀和使用構建到其他 Lucene 應用程序中的索引。此外,很多 Lucene 工具(如Nutch、 Luke)也可以使用Solr 創(chuàng )建的索引。


2、 Tomcat下Solr安裝配置
由于Solr基于java開(kāi)發(fā),因此Solr在windows及Linux都能較好部署使用,但由于Solr提供了一些用于測試及管理、維護較為方便的shell腳本,因此在生產(chǎn)部署時(shí)候建議安裝在Linux上,測試時(shí)候可以在windows使用。

 

下面以L(fǎng)inux下安裝配置Solr進(jìn)行說(shuō)明,windows與此類(lèi)似。
wget http://apache.mirror.phpchina.com/tomcat/tomcat-6/v6.0.16/bin/apache-tomcat-6.0.16.zip
unzip apache-tomcat-6.0.16.zip
mv apache-tomcat-6.0.16 /opt/tomcat
chmod 755 /opt/tomcat/bin/*
wget http://apache.mirror.phpchina.com/lucene/solr/1.2/apache-solr-1.2.0.tgz
tar zxvf apache-solr-1.2.0.tgz

Solr的安裝配置最為麻煩的是對solr.solr.home的理解和配置,主要有三種

 

基于當前路徑的方式
cp apache-solr-1.2.0/dist/apache-solr-1.2.0.war /opt/tomcat/webapps/solr.war
mkdir /opt/solr-tomcat
cp -r apache-solr-1.2.0/example/solr/ /opt/solr-tomcat/
cd /opt/solr-tomcat
/opt/tomcat/bin/startup.sh

由于在此種情況下(沒(méi)有設定solr.solr.home環(huán)境變量或JNDI的情況下),Solr查找./solr,因此在啟動(dòng)時(shí)候需要切換到/opt/solr-tomcat

 

基于環(huán)境變量solr.solr.home
在當前用戶(hù)的環(huán)境變量中(.bash_profile)或在/opt/tomcat/catalina.sh中添加如下環(huán)境變量
export JAVA_OPTS="$JAVA_OPTS -Dsolr.solr.home=/opt/solr-tomcat/solr"

基于JNDI配置
mkdir –p /opt/tomcat/conf/Catalina/localhost
touch /opt/tomcat/conf/Catalina/localhost/solr.xml ,內容如下:

 

Xml代碼
  1. <Context docBase="/opt/tomcat/webapps/solr.war" debug="0" crossContext="true" >  
  2.   <Environment name="solr/home" type="java.lang.String" value="/opt/solr-tomcat/solr" override="true" />  
  3. </Context>  

 

訪(fǎng)問(wèn)solr管理界面 http://ip:port/solr


3、 Solr原理

Solr對外提供標準的http接口來(lái)實(shí)現對數據的索引的增加、刪除、修改、查詢(xún)。在 Solr 中,用戶(hù)通過(guò)向部署在servlet 容器中的 Solr Web 應用程序發(fā)送 HTTP 請求來(lái)啟動(dòng)索引和搜索。Solr 接受請求,確定要使用的適當SolrRequestHandler,然后處理請求。通過(guò) HTTP 以同樣的方式返回響應。默認配置返回Solr 的標準 XML 響應,也可以配置Solr 的備用響應格式。

可以向 Solr 索引 servlet 傳遞四個(gè)不同的索引請求:
add/update 允許向 Solr 添加文檔或更新文檔。直到提交后才能搜索到這些添加和更新。
commit 告訴 Solr,應該使上次提交以來(lái)所做的所有更改都可以搜索到。
optimize 重構 Lucene 的文件以改進(jìn)搜索性能。索引完成后執行一下優(yōu)化通常比較好。如果更新比較頻繁,則應該在使用率較低的時(shí)候安排優(yōu)化。一個(gè)索引無(wú)需優(yōu)化也可以正常地運行。優(yōu)化是一個(gè)耗時(shí)較多的過(guò)程。
delete 可以通過(guò) id 或查詢(xún)來(lái)指定。按 id 刪除將刪除具有指定 id 的文檔;按查詢(xún)刪除將刪除查詢(xún)返回的所有文檔。

一個(gè)典型的Add請求報文

Xml代碼
  1. <add>  
  2.   <doc>  
  3.     <field name="id">TWINX2048-3200PRO</field>  
  4.     <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>  
  5.     <field name="manu">Corsair Microsystems Inc.</field>  
  6.     <field name="cat">electronics</field>  
  7.     <field name="cat">memory</field>  
  8.     <field name="features">CAS latency 2, 2-3-3-6 timing, 2.75v, unbuffered, heat-spreader</field>  
  9.     <field name="price">185</field>  
  10.     <field name="popularity">5</field>  
  11.     <field name="inStock">true</field>  
  12.   </doc>  
  13.   <doc>  
  14.     <field name="id">VS1GB400C3</field>  
  15.     <field name="name">CORSAIR ValueSelect 1GB 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) System Memory - Retail</field>  
  16.     <field name="manu">Corsair Microsystems Inc.</field>  
  17.     <field name="cat">electronics</field>  
  18.     <field name="cat">memory</field>  
  19.     <field name="price">74.99</field>  
  20.     <field name="popularity">7</field>  
  21.     <field name="inStock">true</field>  
  22.   </doc>  
  23. </add> 

一個(gè)典型的搜索結果報文:

Xml代碼
  1. <response>  
  2.     <lst name="responseHeader">  
  3.         <int name="status">0</int>  
  4.         <int name="QTime">6</int>  
  5.         <lst name="params">  
  6.             <str name="rows">10</str>  
  7.             <str name="start">0</str>  
  8.             <str name="fl">*,score</str>  
  9.             <str name="hl">true</str>  
  10.             <str name="q">content:"faceted browsing"</str>  
  11.         </lst>  
  12.     </lst>  
  13.   
  14.     <result name="response" numFound="1" start="0" maxScore="1.058217">  
  15.         <doc>  
  16.             <float name="score">1.058217</float>  
  17.             <arr name="all">  
  18.                 <str>http://localhost/myBlog/solr-rocks-again.html</str>  
  19.                 <str>Solr is Great</str>  
  20.                 <str>solr,lucene,enterprise,search,greatness</str>  
  21.                 <str>Solr has some really great features, like faceted browsing and replication</str>  
  22.             </arr>  
  23.             <arr name="content">  
  24.                 <str>Solr has some really great features, like faceted browsing and replication</str>  
  25.             </arr>  
  26.             <date name="creationDate">2007-01-07T05:04:00.000Z</date>  
  27.             <arr name="keywords">  
  28.                 <str>solr,lucene,enterprise,search,greatness</str>  
  29.             </arr>  
  30.             <int name="rating">8</int>  
  31.             <str name="title">Solr is Great</str>  
  32.             <str name="url">http://localhost/myBlog/solr-rocks-again.html</str>  
  33.         </doc>  
  34.     </result>  
  35.   
  36.     <lst name="highlighting">  
  37.         <lst name="http://localhost/myBlog/solr-rocks-again.html">  
  38.             <arr name="content">  
  39.                 <str>Solr has some really great features, like <em>faceted</em>  
  40.                 <em>browsing</em> and replication</str>  
  41.             </arr>  
  42.         </lst>  
  43.     </lst>  
  44. </response>  

關(guān)于solr的詳細使用說(shuō)明,請參考
http://wiki.apache.org/solr/FrontPage

4、 Solr測試使用

Solr的安裝包包含了相關(guān)的測試樣例,路徑在apache-solr-1.2.0/example/exampledocs

1. 使用shell腳本(curl)測試Solr的操作:
cd apache-solr-1.2.0/example/exampledocs
vi post.sh,根據tomcat的ip、port修改URL變量的值URL=http://localhost:8080/solr/update
./post.sh *.xml                 #

2. 使用Solr的java 包測試Solr的操作:
查看幫助:java -jar post.jar –help
提交測試數據:
java -Durl=http://localhost:8080/solr/update -Ddata=files -jar post.jar  *.xml     

下面以增加索引字段liangchuan、url為例,說(shuō)明一下Solr中索引命令的使用

1) 修改solr的schema,配置需要索引字段的說(shuō)明:
vi /opt/solr-tomcat/solr/conf/schema.xml ,在<fields>中增加如下內容

Xml代碼
  1. <field name="liangchuan"  type="string" indexed="true" stored="true"/>  
  2. <field name="url"  type="string" indexed="true" stored="true"/>  
  1. <field name="liangchuan"  type="string" indexed="true" stored="true"/>  
  2. <field name="url"  type="string" indexed="true" stored="true"/>  


2) 創(chuàng )建增加索引請求的xml測試文件
touch /root/apache-solr-1.2.0/example/exampledocs/liangchuan.xml,內容如下:

Xml代碼
  1. <add>  
  2.   <doc>  
  3.     <field name="id">liangchuan000</field>  
  4.     <field name="name">Solr, the Enterprise Search Server</field>  
  5.     <field name="manu">Apache Software Foundation</field>  
  6.     <field name="liangchuan">liangchuan's solr "hello,world" test</field>  
  7.     <field name="url">http://www.google.com</field>  
  8.   </doc>  
  9. </add>  

3) 提交索引請求
cd apache-solr-1.2.0/example/exampledocs
./post.sh liangchuan.xml

4) 查詢(xún)
通過(guò)solr的管理員界面http://localhost:8080/solr/admin查詢(xún)
或通過(guò)curl 測試:
export URL="http://localhost:8080/solr/select/"
curl "$URL?indent=on&q=liangchuan&fl=*,score"

5、Solr查詢(xún)條件參數說(shuō)明
參數     描述     示例
q    

Solr 中用來(lái)搜索的查詢(xún)??梢酝ㄟ^(guò)追加一個(gè)分號和已索引且未進(jìn)行斷詞的字段的名稱(chēng)來(lái)包含排序信息。默認的排序是 score desc,指按記分降序排序。    
q=myField:Java AND otherField:developerWorks; date asc
此查詢(xún)搜索指定的兩個(gè)字段并根據一個(gè)日期字段對結果進(jìn)行排序。

 

start     將初始偏移量指定到結果集中??捎糜趯Y果進(jìn)行分頁(yè)。默認值為 0。    
start=15
返回從第 15 個(gè)結果開(kāi)始的結果。

 

rows     返回文檔的最大數目。默認值為 10。     rows=25

 

fq     提供一個(gè)可選的篩選器查詢(xún)。查詢(xún)結果被限制為僅搜索篩選器查詢(xún)返回的結果。篩選過(guò)的查詢(xún)由 Solr 進(jìn)行緩存。它們對提高復雜查詢(xún)的速度非常有用。
任何可以用 q 參數傳遞的有效查詢(xún),排序信息除外。

 

hl     當 hl=true 時(shí),在查詢(xún)響應中醒目顯示片段。默認為 false。參看醒目顯示參數上的 Solr Wiki 部分可以查看更多選項     hl=true

 

fl     作為逗號分隔的列表指定文檔結果中應返回的 Field 集。默認為 “*”,指所有的字段?!皊core” 指還應返回記分。    
*,score

其中關(guān)于Solr查詢(xún)相關(guān)的參數詳細的信息請參看:
http://wiki.apache.org/solr/CommonQueryParameters

Solr的查詢(xún)條件參數q的格式與Lucene相同,具體參看:
http://lucene.apache.org/java/docs/queryparsersyntax.html

支持一下吆 請收藏一下:很好

6、 在門(mén)戶(hù)社區中solr使用模式
在門(mén)戶(hù)社區中需要使用solr,可采用如下模式:

 

對原有系統已有的數據或需要索引的數據量較大的情況
直接采用通過(guò)http方式調用solr的接口方式,效率較差,采用solr本身對csv 的支持(http://wiki.apache.org/solr/UpdateCSV
),將數據導出為csv格式,然后調用solr的csv接口http://localhost:8080/solr/update/csv

對系統新增的數據
先將需要索引查詢(xún)的數據組裝成xml格式,然后使用httpclient 將數據提交到solr 的http接口,例如   
http://localhost:8080/solr/update

也可以參考post.jar中的SimplePostTool的實(shí)現。
http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/util/SimplePostTool.java?view=co

 

中文分詞
采用庖丁解牛作為solr(Lucene)缺省的中文分詞方案
項目庫:http://code.google.com/p/paoding/

Google groups:http://groups.google.com/group/paoding
Javaeye的groups:http://analysis.group.javaeye.com/


與nutch的集成使用
http://blog.foofactory.fi/2007/02/online-indexing-integrating-nutch-with.html

嵌入式Solr
http://wiki.apache.org/solr/Solrj#EmbeddedSolrServer

分布式索引
http://wiki.apache.org/solr/CollectionDistribution


7、參考資料
http://wiki.apache.org/solr/
http://www.ibm.com/developerworks/cn/java/j-solr1/
http://www.ibm.com/developerworks/cn/java/j-solr2/
http://www.xml.com/pub/a/2006/08/09/solr-indexing-xml-with-lucene-andrest.html?page=1
http://lucene.apache.org/java/docs/queryparsersyntax.html
http://www.blogjava.net/RongHao/archive/2007/11/06/158621.html

本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
使用 Apache Solr 實(shí)現更加靈巧的搜索,第 1 部分: 基本特性和 Solr 模式
Solr 搭建搜索服務(wù)器
Solr在tomcat下的配置
Solr搜索引擎搭建詳細過(guò)程
開(kāi)發(fā)者都應該知道的開(kāi)源搜索引擎
solr單機安裝使用介紹 V7.4.0
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久