设为首页 收藏本站
查看: 1545|回复: 0

[经验分享] 【Apache Solr系列】Solr QueryElevationComponent--实现竞价排名(手动干预)

[复制链接]

尚未签到

发表于 2015-11-14 08:39:03 | 显示全部楼层 |阅读模式
  转载请注明源地址:http://blog.iyunv.com/weijonathan/article/details/39554579


  


  我们知道。在很多搜索网站上都有这样的一个功能,就是竞价排名,绑定某个关键字,给钱了那我给你排前面。
  包括很多视频网站的一些站内搜索功能也有这样的需求;
  最近在看solr官网,solr的查询功能中就包含了这一功能。参考地址如下:
  https://wiki.apache.org/solr/QueryElevationComponent#elevateIds.2FexcludeIds


  下面这个网址包含了solr所有功能;对solr感兴趣的可以收藏下!
  https://cwiki.apache.org/confluence/display/solr/Spell+Checking


  那么接下来我们来实现我们的功能把。
  solrconfig.xml
  

<searchComponent name=&quot;elevator&quot;
class=&quot;org.apache.solr.handler.component.QueryElevationComponent&quot;>
<!-- pick a fieldType to analyze queries -->
<str name=&quot;queryFieldType&quot;>string</str>
<str name=&quot;config-file&quot;>elevate.xml</str>
</searchComponent>
<!-- A request handler for demonstrating the elevator component -->
<requestHandler name=&quot;/elevate&quot;
class=&quot;org.apache.solr.handler.component.SearchHandler&quot; startup=&quot;lazy&quot;>
<lst name=&quot;defaults&quot;>
<str name=&quot;echoParams&quot;>explicit</str>
<!-- <str name=&quot;df&quot;>text</str> -->
</lst>
<arr name=&quot;last-components&quot;>
<str>elevator</str>
</arr>
</requestHandler>
  
  config-file:elevate.xml,这个文件solr默认已经存在,需要自己配置;默认跟solrconfig.xml同一目录,如无特殊要求可不做修改
  searchComponent的name属性是和requestHandler有一个绑定关系的,大家注意一下;
  还有就是,requestHandler定义的名称/elevate是我们后面需要用到的节点名,就像selelct一样。使用这一功能的时候把select换成elevate。

requestHandler标签中的defaults-->df是定义了你要做竞价排名,或者说人工干预的查询字段;如果此处不指定的话,需要在查询的时候指定;


  



<elevate>
<query text=&quot;isle&quot;>
<doc id=&quot;6493&quot; />  <!-- put the actual ipod at the top -->
<doc id=&quot;3971&quot; exclude=&quot;true&quot; /> <!-- exclude this cable -->
</query>
</elevate>以上是一个简单的示例,当用户查询isle时,docID为6493的文档会被提到最前。而这里的docID为3971的文档将会被提出到查询的结果之外,因为配置了exclude属性为true。  
  如果不配置默认为false,即不排除!
  接下来我们查询下看看。这里先看下正常的查询结果。这里我们把enableElevation设置为false即可
  

<response>
<lst name=&quot;responseHeader&quot;>
<int name=&quot;status&quot;>0</int>
<int name=&quot;QTime&quot;>1</int>
<lst name=&quot;params&quot;>
<str name=&quot;enableElevation&quot;>false</str>
<str name=&quot;df&quot;>name</str>
<str name=&quot;q&quot;>isle</str>
<str name=&quot;forceElevation&quot;>true</str>
</lst>
</lst>
<result name=&quot;response&quot; numFound=&quot;6&quot; start=&quot;0&quot;>
<doc>
<str name=&quot;id&quot;>302</str>
<str name=&quot;name&quot;>The Isle</str>
<str name=&quot;year&quot;>2001</str>
<long name=&quot;_version_&quot;>1480190152307376130</long>
</doc>
<doc>
<str name=&quot;id&quot;>2</str>
<str name=&quot;name&quot;>Isle of Man TT 2004 Review</str>
<str name=&quot;year&quot;>2004</str>
<long name=&quot;_version_&quot;>1480190152202518528</long>
</doc>
<doc>
<str name=&quot;id&quot;>6493</str>
<str name=&quot;name&quot;>Val Lewton: Isle of the Dead / Bedlam</str>
<str name=&quot;year&quot;>1945</str>
<long name=&quot;_version_&quot;>1480190153170354189</long>
</doc>
<doc>
<str name=&quot;id&quot;>3871</str>
<str name=&quot;name&quot;>The Who: Live at the Isle of Wight Festival</str>
<str name=&quot;year&quot;>1970</str>
<long name=&quot;_version_&quot;>1480190152951201796</long>
</doc>
<doc>
<str name=&quot;id&quot;>9409</str>
<str name=&quot;name&quot;>Isle of Wight Festival: Message to Love: 1970</str>
<str name=&quot;year&quot;>1970</str>
<long name=&quot;_version_&quot;>1480190153367486468</long>
</doc>
<doc>
<str name=&quot;id&quot;>13617</str>
<str name=&quot;name&quot;>
Jethro Tull: Nothing Is Easy: Live at the Isle of Wight 1970
</str>
<str name=&quot;year&quot;>2005</str>
<long name=&quot;_version_&quot;>1480190153579298828</long>
</doc>
</result>
</response>

接下来我们把enableElevation设置为true,查询做下对比  
  http://localhost:8081/solr/collection1/elevate?q=isle&enableElevation=true&forceElevation=true


  查询结果如下:’
  

<response>
<lst name=&quot;responseHeader&quot;>
<int name=&quot;status&quot;>0</int>
<int name=&quot;QTime&quot;>18</int>
<lst name=&quot;params&quot;>
<str name=&quot;enableElevation&quot;>true</str>
<str name=&quot;df&quot;>name</str>
<str name=&quot;q&quot;>isle</str>
<str name=&quot;forceElevation&quot;>true</str>
</lst>
</lst>
<result name=&quot;response&quot; numFound=&quot;6&quot; start=&quot;0&quot;>
<doc>
<str name=&quot;id&quot;>6493</str>
<str name=&quot;name&quot;>Val Lewton: Isle of the Dead / Bedlam</str>
<str name=&quot;year&quot;>1945</str>
<long name=&quot;_version_&quot;>1480190153170354189</long>
</doc>
<doc>
<str name=&quot;id&quot;>302</str>
<str name=&quot;name&quot;>The Isle</str>
<str name=&quot;year&quot;>2001</str>
<long name=&quot;_version_&quot;>1480190152307376130</long>
</doc>
<doc>
<str name=&quot;id&quot;>2</str>
<str name=&quot;name&quot;>Isle of Man TT 2004 Review</str>
<str name=&quot;year&quot;>2004</str>
<long name=&quot;_version_&quot;>1480190152202518528</long>
</doc>
<doc>
<str name=&quot;id&quot;>3871</str>
<str name=&quot;name&quot;>The Who: Live at the Isle of Wight Festival</str>
<str name=&quot;year&quot;>1970</str>
<long name=&quot;_version_&quot;>1480190152951201796</long>
</doc>
<doc>
<str name=&quot;id&quot;>9409</str>
<str name=&quot;name&quot;>Isle of Wight Festival: Message to Love: 1970</str>
<str name=&quot;year&quot;>1970</str>
<long name=&quot;_version_&quot;>1480190153367486468</long>
</doc>
<doc>
<str name=&quot;id&quot;>13617</str>
<str name=&quot;name&quot;>
Jethro Tull: Nothing Is Easy: Live at the Isle of Wight 1970
</str>
<str name=&quot;year&quot;>2005</str>
<long name=&quot;_version_&quot;>1480190153579298828</long>
</doc>
</result>
</response>可以看到docID为6493的文档被提到最前。而docID为3971的文档被剔除结果集。


  
  好了,到这基本上功能就完成了。有什么不对的地方请多加指点;
  



版权声明:本文为博主原创文章,未经博主允许不得转载。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-138989-1-1.html 上篇帖子: 从零开始学习,Apache Spark源码走读(一) 下篇帖子: 使用Apache CXF搭建REST风格的Web Service
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表