0

The Solr "qf" parameter works as follows:

Let's say I have: query = "sid" and qf = [field1, field1_edge, field2, field2_edge].

The Solr score is calculated as follows:

max(f1, f1_e, f2, f2_e) + tie * (sum of other 3 fields) where: "tie" lies in [0,1]

Let's call: winner1 = field with max(f1, f1_e) and winner2 = field with max(f2, f2_e)

I would like to score a given query in Solr as follows:

score1 = winner1_score + tie_1 * loser1_score
score2 = winner2_score + tie_1 * loser2_score

final score = score1 + tie_2 * score2

Effectively, I want to apply qf in two layers (taking tie_1 = 0 and tie_2 = 1). What are my options to implement this idea of relevance? I think neither "qf" parameter nor function boosts support this. Thanks!

  • Are you asking how you can use the separate scores as calculated for each field, or how you can use the `max()` function with the values (as stored in the fields named `field1_score`, etc.) from multiple predefined fields as the score? – MatsLindh Dec 27 '18 at 12:49
  • @MatsLindh Basically, I am interested in using scores of different fields to compare them in discrete steps. For example, in step 1, I want to compare scores from 2 differing forms of a particular `field` and decide which one to consider. In step 2, I want to take the winners of step 1 for different fields and compare them. – sidharth228 Dec 27 '18 at 13:15
  • But the scores for each field should be computing using normal scoring? Would this be similar to using the `dismax` or `edismax` query parsers? (which creates disjunct queries and uses the max from each sub query as the query's score) – MatsLindh Dec 27 '18 at 13:42
  • Yes each field is scored using normal scoring using any of DisMax or eDisMax parser. I want to create disjunct queries and take max from each subquery more than once. – sidharth228 Dec 28 '18 at 06:21
  • I fail to see the difference - max(s1, s2) is the same as `max(field1_score, field1_edge_score, field2_score, score_field2_edge_score)` which is the same as taking the max from each sub query, isn't it? And "taking the max more than once" would still be the same max, wouldn't it? Can you add examples showing what you want that differs from what the dismax query parsers provide and proper examples of how you'd expect a query to be scored in your example? – MatsLindh Dec 28 '18 at 07:17
  • @MatsLindh I've updated the description. I hope it helps. – sidharth228 Dec 28 '18 at 12:52

1 Answers1

1

It seems to me that's the way to do it is to use the query function which allows you to apply functions to queries. You combine this with nested query parsers which allows you to run multiple dismax queries.

You can do something like this (where you set tie1 and tie2 according to what you want):

q=_val_:"add(query($qq1),product(query($qq2),${tie2}))"
qq1={!edismax qf='field1 field1_edge' v='sid' tie=${tie1}}
qq2={!edismax qf='field2 field2_edge' v='sid' tie=${tie1}}
tie1=0.5
tie2=0.3

If you used Solr 7.2 (or higher) you also need to set uf=_query_ * in order for the _val_ hook to work.

P.S: it should be possible (though I haven't tested it) to move the content of q into the qf parameter and that way you don't have to use the _val_ hook:

qf=add(query($qq1),product(query($qq2),${tie2}))

Tomer Arazy
  • 1,833
  • 10
  • 15
  • This is a good answer and works as advertised under solr 6.6. Note that putting the functions directly in the `qf` field did not work for me. – jvd10 Mar 25 '21 at 15:00