zoukankan      html  css  js  c++  java
  • solr搜索打分规制排序

    转自:http://www.iteye.com/topic/1126944

    solr使用了Lucene的内核,也继承了Lucene的打分规则,关于Lucene打分规则可以参考如下博客

    http://blog.chenlb.com/2009/08/lucene-scoring-architecture.html

    Solr内改变打分规则有几种形式:

    1.配置solr的solrconfig.xml中edismax,来改变Boost打分规则

    2.在solr的schema中增加一个字段,该字段专门用于排序

    3.自写一个solr的评分规则。

    一般简单的应用1和2就能满足。

    举一个例子,电商类网站(比如淘宝)的商品搜索:

    1.在商品名称上出现搜索关键字排序靠前,而内容的次之

    2.对多皇冠的买家排序靠前等

    3.对近期发布的商品排序靠前

    4.对最近销售多商品靠前

    综上获得一个综合排名

    在solrconfig.xml的SearchHandler中如下配置

    Xml代码  收藏代码
    1. <requestHandler name="standard" class="solr.StandardRequestHandler" default="true" >  
    2.     <lst name="defaults">  
    3.         <str name="echoParams">explicit</str>  
    4.         <str name="rows">10</str>  
    5.         <str name="hl">on</str>  
    6.         <str name="hl.fl">name,content</str>  
    7.         <str name="f.content.hl.fragsize">200</str>  
    8.         <str name="defType">edismax</str>  
    9.         <str name="bf">  
    10.             sum(recip(ms(NOW,pub_date),1,1,100),div(point,5632000),div(sale_count,1000000))  
    11.         </str>         
    12.         <str name="pf">  
    13.             content  
    14.         </str>         
    15.         <str name="qf">  
    16.             name^1.9   
    17.         </str>  
    18.     </lst>  
    19. </requestHandler>  

     bf用函数计算某个字段的权重,如上例子中pub_date发布日期的权重,point比如诚信指数,sale_count销售数量

    bf内字段必须是索引的,bf的函数查看solr api文档 http://wiki.apache.org/solr/FunctionQuery

    pf查询字段,这样在schema不用制定默认字段

    qf对默认查询增加权重比值,比如标题是content的1.9倍,值越大权重越大

    这样查询就会计算如下的一个综合评分值了

    对于其他排序,比如说价格排序,在schema增加price字段,然后查询是增加sort=price desc就可以了

  • 相关阅读:
    Spring Aop实例之xml配置
    Spring execution 表达式
    JVM调优总结 -Xms -Xmx -Xmn -Xss
    springmvc整合redis架构搭建实例
    mysql权限操作(转)
    mybatis动态排序
    spring mvc重定向
    jquery中bind和on的区别
    在java项目中使用umeditor
    mybatis的基础Dao
  • 原文地址:https://www.cnblogs.com/liuguanghuiyes/p/3072762.html
Copyright © 2011-2022 走看看