获取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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
solr 下没有任何聚合函数,就像您从 SQL 中思考它们的方式一样。最简单的方法是分两步进行:
因此,类似于:
...获取具有 max view_count 的项目,您将其记录在某处,然后
请注意 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:
So, something like:
...to get an item with the max view_count, which you record somewhere, and then
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).
您可以只添加:
&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