Question

Am trying to boost records with a particular date in the future closest to now towards the top of the results, and make those with dates in the past less relevant. I've seen a number of posts about how to boost results which are just closer to now, but that's not really what I need.

Was it helpful?

Solution

What you want to do is:

  1. Know if the date is in the future or the past
  2. Use different boost functions for each case

Assuming the field name is due_date, we'll start building your query.

First, you want to get the time difference.

&timediff=ms(due_date,NOW)

You can use NOW/HOUR, NOW/DAY for better performance

Second, we need to know if duration is positive or negative: adding a number to its absolute value will return 1/true on positive and 0/false on negative.

&future=sum($timediff,abs($timediff)

Now depending whether the number is positive or negative you want to apply different boost functions. You can use any function you want here.

&futureboost=recip($timediff,1,36000000,36000000)
&pastboost=recip($timediff,1,3600000,3600000)
$finalboost=if($future,$futureboost,$pastboost)
&boost=$finalboost

Notice that futureboost parameters are 10x more than pastboost which will give higher boost to future documents than past ones. The recip function is documented on the Solr Function Query page and you can tune the parameters of both futureboost and pastboost functions to your case.

To return the function value, you can use:

&fl=_DATE_BOOST_:$finalboost

Full Query will be a combination of all the above:

&timediff=ms(due_date,NOW/HOUR)
&future=sum($timediff,abs($timediff)
&futureboost=recip($timediff,1,36000000,36000000)
&pastboost=recip($timediff,1,3600000,3600000)
$finalboost=if($future,$futureboost,$pastboost)
&boost=$finalboost
&fl=_DATE_BOOST_:$finalboost

OTHER TIPS

Solved it by applying the below boost query :

bq=movie_release_date:[NOW/DAY-1MONTH TO NOW/DAY+2MONTHS]^10

Not that accurate as the previous answer, but in case you lack Solr 4, it results pretty much the same.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top