I have a Solr (6.2) DisMax Select Query which uses pf (phrase fields) and ps (phrase slop).
pf = text^2.2 title^2.2, ps = 2
;
I want my query to return results following this algorithm:
- If there are exact matches for the queried phrase, return them first, sort by date
- If there are documents that have atleast one of the words of the queried phrase, return them second, sort by date
Example Data: text (last_modified timestamp in parenthesis)
- stuff about important people (2018)
- important people: the article (2019)
- some people find that important (2020)
- important news (2015)
- people of the decade (2020)
The desired result:
phrases with acceptable slop first
- some people find that important (2020)
- important people: the article (2019)
- stuff about important people (2018)
then at least one of the words
- people of the decade (2020)
- important news (2015)
What i've tried:
- wrapping a query into double quotes and using
qs
(query phrase slop), this way it works as desired, but ignores the "at least on of the words" part; - using a bq (boost query) like
last_modified:[NOW/DAY-3MONTH TO NOW/DAY]^20.0
; - using a bf (boost function) like
recip(ms(NOW,last_modified),3.16e-11,1,1)
; - explicit
last_modified desc
sort - but it ignores the score completely - using multiple sort
score desc, last_modified desc
- but the second sort will work only if there is a tie for the first one (and there is almost never a tie)