solr 相似查询-MoreLikeThis

时间:2014-10-10 16:21:05   收藏:0   阅读:1068

参考文档:

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

 

原文:http://www.cnblogs.com/a198720/p/4016052.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!