標籤:des Lucene style blog http color io os 使用
參考文檔:
MoreLikeThis
MoreLikeThisHandler
在solr中有兩種方式實現MoreLikeThis:
第一種:SearchHandler中的MoreLikeThisComponent,MoreLikeThis以組件的身份出現,適於簡單應用。
第二種:MoreLikeThisHandler,MoreLikeThis作為一個單獨的Handler來處理,可以應用過濾等較複雜操作
1、採用相似查詢的field的儲存方式最好採用TermVectors方式,如果field沒有採用TermVectors方式,MoreLikeThis將會從store儲存中產生terms。
<field name="cat" ... termVectors="true" />
2、參數說明:
或者:
<str name="mlt.qf"> text^0.5 features^1.0 name^1.2 sku^1.5 id^10.0 manu^1.1 cat^1.4 title^10.0 description^5.0 keywords^5.0 author^2.0 resourcename^1.0 </str>
第一種方法:morelikeThis組件為response中的每一個document返回相似查詢文檔,也許這應該叫做"MoreLikeThese"。
例子:
http://localhost:8983/solr/select?q=apache&mlt=true&mlt.fl=manu,cat&mlt.mindf=1&mlt.mintf=1&fl=id,score
第二種方法:當你只需要相似查詢的相關資訊時,可以使用MoreLikeThisHandler。
MoreLikeThisHandler具有以下參數:
|
rows |
控制返回結果的最大數量 |
|
mlt.match.include |
結果集中是否包含原始的文檔 |
|
mlt.match.offset |
By default, the MoreLikeThis query operates on the first result for ‘q‘ |
|
mlt.interestingTerms |
值:"list", "details", "none" --顯示相似查詢中使用到的相關的terms。這些terms時最佳評選的terms。如果選擇‘details‘,將會顯示每個term的權值。 |
見MoreLikeThis額外的輸入參數。
MoreLikeThisHandler同樣也可以使用ContentStream來尋找相似文檔。它將會從發送過來的文本中抽取相關terms。
樣本:
<requestHandler name="/mlt" class="solr.MoreLikeThisHandler"> <lst name="defaults"> <str name="mlt.fl">title</str> <str name="mlt.mintf">1</str> <str name="mlt.minwl">2</str> <int name="rows">3</int> </lst> </requestHandler>
其中<lst name="defaults"> 時查詢時預設的參數值,可有可無。
簡單例子:
http://localhost:8983/solr/mlt?q=id:UTF8TEST&mlt.fl=manu,cat&mlt.mindf=1&mlt.mintf=1
http://localhost:8983/solr/mlt?q=id:UTF8TEST&mlt.fl=manu,cat&mlt.mindf=1&mlt.mintf=1&mlt.match.include=false
http://localhost:8983/solr/mlt?q=id:SP2514N&mlt.fl=manu,cat&mlt.mindf=1&mlt.mintf=1&fq=inStock:true&mlt.interestingTerms=details
使用ContentStreams:
If you post text in the body, that will be used for similarity. Alternatively, you can put the posted content in the URL using something like:
http://localhost:8983/solr/mlt?stream.body=electronics%20memory&mlt.fl=manu,cat&mlt.interestingTerms=list&mlt.mintf=0
If remoteStreaming is enabled, you can find documents similar to the text on a webpage:
http://localhost:8983/solr/mlt?stream.url=http://lucene.apache.org/solr/&mlt.fl=manu,cat&mlt.interestingTerms=list&mlt.mintf=0
solr 相似查詢-MoreLikeThis