Getting maximum field value in solr

I would like to increase my query by the number of views of the element; For this purpose, I would like to use something like view_count / max_view_countthat to be able to evaluate how counting an element's point relates to the most views in the index. I know how to improve results with a function query , but how can I easily get the maximum viewing score? If anyone could provide an example, that would be very helpful ...

+5
source share
2 answers

There are no aggregate functions under solr in how you can think of them from SQL. The easiest way to do this is to perform a two-step process:

  • Get the maximum value through the corresponding query using sorting
  • use it with max () function

So something like:

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

... to get the element with max view_count that you are recording somewhere and then

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

Note that the max () function does not execute the aggregate maximum; just by getting the maximum maximum number of views you transmit, or 1 (to avoid errors with separate errors).

multiValued ( ), StatsComponent, . , , , , (, -, ).

+9

: & ; = & stats.field = view_count .

+5

All Articles