Apache Solr实现竞价排名

如果想在solr实现像百度一样相似的竟价的排名,也是可以的,在solr中实现竟价排名,主要使用QueryElevationComponent组件,

solrconfig.xml配置:
<searchComponent name="elevator" class="solr.QueryElevationComponent">  
<!-- pick a fieldType to analyze queries -->
<str name="queryFieldType">string</str>
<str name="config-file">elevate.xml</str>
</searchComponent>

<!-- a request handler utilizing the elevator component -->
<requestHandler name="/elevate" class="solr.SearchHandler" startup="lazy">
<lst name="defaults">
<str name="defType">myqueryparser</str>
<str name="echoParams">explicit</str>
</lst>
<arr name="last-components">
<str>elevator</str>
</arr>
</requestHandler>


通过相应的URL:  

http://localhost:8088/solr/elevate?q=天山长宁&enableElevation=true&forceElevation=true&exclusive=true&debugQuery=true

Solr中实现竟价排名,要竞价的文档通过配置文件elevate.xml进行设置,此文件可以放在solr/data下,也可以放在solr/conf下,

elevate.xml配置:
<elevate> 
<query text="hellip">
<doc id="143702"/>
<doc id="143328"/>
<!-- doc id="143701" exclude="true"/-->
</query>
<query text="天山长宁">
<doc id="35206"/>
<doc id="57515"/>
<!-- doc id="143701" exclude="true"/-->
</query>
</elevate>


通过配置关键字和相应的ID,就可以把指定的文档放到最前面,这里把"天山长宁",放在关键字中,能过查询"天山长宁",会把包括"天山长宁"的文档中id:35206,id:57515排在最前面,同时也可以去除指定的文档,如上可以通过exclude="true" 参数,不显示指定的文档. 

搜索结果如下图

(来源:在http://xyliufeng.iteye.com/blog/772459基础上进行阅读美化)

原文地址:https://www.cnblogs.com/ibook360/p/2266233.html