在solr中获取字段的最大值 [英] Getting maximum value of field in solr

查看:411
本文介绍了在solr中获取字段的最大值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过商品的观看次数来增加查询量;为此,我想使用类似view_count / max_view_count的名称,以便能够衡量项目的视图计数与索引中最大视图计数的关系.我知道如何通过函数查询来增强结果,但是如何轻松获得最大观看次数?如果有人可以提供示例,那将非常有帮助...

I'd like to boost my query by the item's view count; I'd like to use something like view_count / max_view_count for this purpose, to be able to measure how the item's view count relates to the biggest view count in the index. I know how to boost the results with a function query, but how can I easily get the maximum view count? If anybody could provide an example it would be very helpful...

推荐答案

solr下没有任何聚合函数,就像您可能从SQL考虑它们的方式一样.最简单的方法是分两步进行:

There aren't any aggregate functions under solr in the way you might be thinking about them from SQL. The easiest way to do it is to have a two-step process:

  • 通过带有排序的适当查询获取最大值
  • 与max()函数一起使用

所以,像这样:

q=*:*&sort=view_count desc&rows=1&fl=view_count

...获得一个具有最大view_count的项目,然后将其记录在某处,然后

...to get an item with the max view_count, which you record somewhere, and then

q=whatever&bq=div(view_count, max(the_max_view_count, 1))

请注意,max()函数未执行合计最大值;只是获得您传入的最大观看次数的最大值或1(以避免被零除错误).

Note that that max() function isn't doing an aggregate max; just getting the maximum of the max-view-count you pass in or 1 (to avoid divide-by-zero errors).

如果您有一个多值字段(无法排序),则也可以使用 StatsComponent 以获取最大值无论哪种方式,您都可能只想执行一次,而不是针对每个查询(例如,每天晚上在午夜或数据集建立之后的任何一次)执行一次.

If you have a multiValued field (which you can't sort on) you could also use the StatsComponent to get the max. Either way, you would probably want to do this once, not for every query (say, every night at midnight or whatever once your data set settles down).

这篇关于在solr中获取字段的最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆