Boost Recent Results: Freshness in Solr Queries

Solr API

A freshness boost multiplies the score of each result by a number that falls as the document gets older. A new, relevant page beats an old, relevant one; a strong old match still beats a weak new one.

01 · The boost

q={!boost b=$fresh v=$mainQuery}
fresh=recip(max(0,ms(NOW,creation_date)),1.212e-9,1,1)
mainQuery={!hybrid lexical=$lexicalQuery vector=$vectorQuery mode=union alpha=0.85 topN=500}
fq=creation_date:[* TO *]

recip(x, c, 1, 1) is 1 ÷ (c × x + 1), where x is the age of the document in milliseconds. The factor is 1 for a document dated now and halves when x = 1 ÷ c: with c = 1.212e-9, after about 9.6 days. This is the boost of Fresh on the hosted search page at its default strength. {!boost} multiplies the whole score, so it reaches every result, those found by meaning included.

The filter fq=creation_date:[* TO *] leaves out documents without a date: for them the age counts as 0 and they would get the full boost.

02 · Choose the half-life

Half-lifecEffect
365 days3.171e-11The date barely matters.
41 days2.822e-10Gentle.
9.6 days1.212e-9The default of the hosted search page.
2.2 days5.203e-9Strong.
6 hours4.63e-8The newest matching page wins almost regardless of relevance.

For any half-life, c = 1 ÷ (the half-life in milliseconds).

03 · Boost or filter

A date filter such as fq=creation_date:[NOW-30DAYS TO *] hides everything older. The boost hides nothing and only changes the order. Use the filter for a "last month" choice, the boost for "newer first".

04 · On the hosted search page

Visitors turn the boost on with the Fresh switch; you choose how strong it is with Fresh Results Bias Weight. Next to it, the AI switch turns meaning on or off for one visitor and shows in the address as ai=yes or ai=no. When your Search Mode is Lexical Only, the plan of the index owner has no AI, or the AI requests of the month are used, the switch is hidden and ai=yes is ignored.