solr 相似查詢-MoreLikeThis

來源:互聯網
上載者:User

標籤: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、參數說明:

  • mlt.fl    :設定相似查詢欄位,最好採用TermVectors儲存。
  • mlt.mintf   :最小分詞頻率,來源文件中小於該頻率的分詞將被忽略掉。tf:分詞後的詞在該文檔中的頻率
  • mlt.mindf   : 最小文檔頻率,該詞所在文檔的個數小於這個值時將不用於相似判斷。df:該詞所在文檔的個數。
  • mlt.minwl :詞的最小長度,當詞的長度小於該值時不用於相似判斷。
  • mlt.maxwl  :詞的最大長度,當詞的長度大於該值時不用於相似判斷。
  • mlt.maxqt  :構造相似查詢的terms的最大數量。
  • mlt         : true ,開啟相似查詢。
  • mlt.count   :為每一個相似查詢結果返回指定數量的相似文檔。
  • mlt.boost :相似查詢是否開啟加權功能。true/false
  • mlt.qf     :相似查詢field欄位加權設定。

    如:mlt.qf=text^0.5 features^1.0 name^1.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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.