Boost Solr documents by age

The simplest way of boosting documents by age is by applying a reverse sort on age. If that's possible, then you're done!

In other cases where what you're after is a boost and not a sort, then read on!

The general idea here is to boost more recent documents and penalize older documents.

Example schema


<fieldType name="tdate" class="solr.TrieDateField" 
  omitNorms="true" precisionStep="6" positionIncrementGap="0"/>
 
<field name="modify_date" type="tdate" indexed="true" stored="true" required="true" />

Query

There are a number of ways to boost using functionqueries. One way is: recip + linear, where recip computes an age-based score, and linear is used to boost it.

The dismax query parser provides and easy way to apply boost functions. For example:


http://localhost:8983/solr/search?qt=dismax&q=search&bf=linear(recip(rord(modify_date),1,1000,1000),11,0)

Another way is recip + ms:


http://localhost:8983/solr/search?qt=dismax&q=search&bf=recip(ms(NOW/HOUR,modify_date),3.16e-11,0.08,0.05)

or

http://localhost:8983/solr/search?qt=dismax&q=search&bf=recip(ms(NOW,modify_date),3.16e-11,1,1)

Try a couple variations. Your mileage may vary.