获取solr中字段的最大值

发布于 2024-11-16 19:04:30 字数 291 浏览 2 评论 0原文

我想通过该项目的查看次数来提高我的查询;为此,我想使用诸如 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...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

兔姬 2024-11-23 19:04:30

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

  • 通过适当的查询和排序获取最大值
  • 将其与 max() 函数结合使用

因此,类似于:

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

...获取具有 max view_count 的项目,您将其记录在某处,然后

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

请注意 max() 函数并未执行聚合 max;只是获取您传入的 max-view-count 的最大值或 1(以避免被零除错误)。

如果您有一个多值字段(无法对其进行排序),您还可以使用 StatsComponent以获得最大值。无论哪种方式,您可能都希望执行一次此操作,而不是对每个查询执行此操作(例如,每天晚上午夜或数据集稳定下来后的任何时间)。

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:

  • Get the max value via an appropriate query with a sort
  • use it with the max() function

So, something like:

q=*:*&sort=view_count desc&rows=1&fl=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))

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).

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).

等风来 2024-11-23 19:04:30

您可以只添加:
&stats=true&stats.field=view_count
您将看到有关该指定字段的小统计信息。更多文档此处

You can add just:
&stats=true&stats.field=view_count
You will see a small statistics on that specified field. More documentation here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文