Hello,
I’m looking for the most efficient way to specify sorting on expressions when 
they’re complex.
For example, suppose that there are fields a1, a2, ….., an and I need to sort 
for the sum of them. In this case it’s “easy” using 
sum(def(a1,0),def(a2,0),…,def(an,0)) as expression.
Now suppose there are also fields b1, b2, …. bm, and I want to sort by the 
ratio between the sum of all a(s) and the sum of b(s) i.e. 
div(sum(def(a1,0),def(a2,0),…,def(an,0)), sum(def(b1,0),def(b2,0),…,def(bm,0))).
This expression works but it can cause a division by zero. So, supposing we 
want zero as the result when the sum of all b(s) is zero, the sorting 
expression becomes

if ( sum(def(b1,0),def(b2,0),…,def(bm,0)), 
div(sum(def(a1,0),def(a2,0),…,def(an,0)), 
sum(def(b1,0),def(b2,0),…,def(bm,0))), 0)

is this efficient, i.e. does solr recognize that there are two subexpression 
that are the same and calculate them just once ?
Does a better way to do this exist ?

A similar question can be asked for json stats.

Thanks!
— 
Ing. Andrea Vettori
Sistemi Informativi
B2BIres s.r.l.

Reply via email to