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

[经验分享] Solr 自定义排序[1]

[复制链接]
累计签到:6 天
连续签到:1 天
发表于 2015-7-16 13:55:11 | 显示全部楼层 |阅读模式
  需求:商品排序,无库存的商品排在后面(排序)。
  
  搜索:
   默认搜索:                                            df:
DSC0000.png        DSC0001.png
  可以看出左图第1个、第6个库存为0.
  现在的需求是想将这两个库存为0的商品排在最后面。
  edismax-》bf:product(map(store,1,9999999,1),100) ,效果如右图。
  store map的规则:
  store=0,v(store)=0;
  store>0,v(store)=1;(默认store的最大值999999999)
  product*100,为了突显加权的效果。(可忽略)
  以上等同于:
  q: queryStr_val_:"product(map(store,1,9999999,1),100)"
  
  观察打分的细节:




12.634275 = (MATCH) sum of:
2.0679202 = (MATCH) sum of:
1.2457463 = (MATCH) weight(searchField:165 in 18377) [DefaultSimilarity], result of:
1.2457463 = score(doc=18377,freq=2.0 = termFreq=2.0
), product of:
0.77180904 = queryWeight, product of:
7.3044024 = idf(docFreq=78, maxDocs=43211)
0.105663545 = queryNorm
1.6140602 = fieldWeight in 18377, product of:
1.4142135 = tf(freq=2.0), with freq of:
2.0 = termFreq=2.0
7.3044024 = idf(docFreq=78, maxDocs=43211)
0.15625 = fieldNorm(doc=18377)
0.82217383 = (MATCH) weight(searchField:清爽 in 18377) [DefaultSimilarity], result of:
0.82217383 = score(doc=18377,freq=2.0 = termFreq=2.0
), product of:
0.6270135 = queryWeight, product of:
5.934057 = idf(docFreq=310, maxDocs=43211)
0.105663545 = queryNorm
1.3112538 = fieldWeight in 18377, product of:
1.4142135 = tf(freq=2.0), with freq of:
2.0 = termFreq=2.0
5.934057 = idf(docFreq=310, maxDocs=43211)
0.15625 = fieldNorm(doc=18377)
10.566355 = (MATCH) FunctionQuery(product(map(int(store),1.0,9999999.0,const(1)),const(100))), product of:
100.0 = product(map(int(store)=10,min=1.0,max=9999999.0,target=const(1)),const(100))
1.0 = boost
0.105663545 = queryNorm


  从上可以大致看出总分12.634275为文本分2.0679202加上库存加分10.566355。
  

  
  
  扩展阅读:
  http://wiki.apache.org/solr/DisMax
DisMax is an abbreviation Disjunction Max, and is a popular query mode with Solr.
Simply put, it's your choice for all user generated queries.
Out of the box, Solr uses the standard Solr query parser which is pretty stupid, understanding only syntactically correct boolean queries like "title:foo OR body:foo", it can only search one field by default, and it may very well throw an exception in your face if you put in some characters it does not like.
Therefore a new, more robust query mode was needed and the DisMax and ExtendedDisMax Query Parsers were born. They are designed to process simple user entered phrases (without heavy syntax) and search for the individual words across several fields using different weighting (boosts) based on the significance of each field, and it should never throw an exception.
Disjunction refers to the fact that your search is executed across multiple fields, e.g. title, body and keywords, with different relevance weights
Max means that if your word "foo" matches both title and body, the max score of these two (probably title match) is added to the score, not the sum of the two as a simple OR query would do. This gives more control over your ranking.
DisMax is usually the short name for the actual query parser, so don't be confused. The old DisMax parser has been around for some time, while the new and more advanced ExtendedDisMax parser was introduced in DSC0002.png Solr3.1 as experimental.
There is a Lucid Imagination Blog post that explains the origins and conceptual behavior of dismax functionality.
  
  

  
  FunctionQuery:
  http://wiki.apache.org/solr/FunctionQuery#map
  ExtendedDisMax[edisMax]:
  http://wiki.apache.org/solr/ExtendedDisMax
  

运维网声明 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-87354-1-1.html 上篇帖子: solr搜索异常 下篇帖子: solr安装
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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