Hello, we’re using Solr as the backend for a sort of Business Intelligence frontend and it’s working very well for our needs. Each document in Solr contains some basic data and a lot of dynamic fields that are used as measures. Part of the field name is related to the “time” of the data it contains, for example the field xxx_2023_11 is the value of xxx for year 2023 and month 11. When we query the system we need to calculate sum or average or other more complex expressions on the data for specific range of times that are not know in advance, so we can’t create the data at index time (doing all combinations would increase exponentially the number of fields).
So my question is, when using complex expressions is Solr smart enough to see common subexpressions and calculate them only once or is there a way to “specify” common expressions to help Solr processing them more efficiently ? Thanks! — Ing. Andrea Vettori Sistemi Informativi B2BIres s.r.l. > On 1 Nov 2023, at 13:24, Alessandro Benedetti <benedetti.ale...@gmail.com> > wrote: > > I suspect this is an XY problem, can you elaborate better what's the > original task to be solved? > It's unusual to use those sort expressions in Solr. > > Maybe we can solve it differently, at indexing time or maybe using some > ranking models (like a linear one on learning to rank, but using not > learned multipliers). > > Cheers > > On Wed, 1 Nov 2023, 09:40 Ing. Andrea Vettori, <a.vett...@b2bires.com> > wrote: > >> 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. >> >>