SOLR - Boost function (bf) to increase score of do

2020-05-20 03:04发布

I have a solr instance containing documents which have a 'startTime' field ranging from last month to a year from now. I'd like to add a boost query/function to boost the scores of documents whose startTime field is close to the current time.

So far I have seen a lot of examples which use rord to add boosts to documents whom are newer but I have never seen an example of something like this.

Can anyone tell me how to do it please?

Thanks

标签: lucene solr
2条回答
▲ chillily
2楼-- · 2020-05-20 03:45
放荡不羁爱自由
3楼-- · 2020-05-20 03:52

If you're on Solr 1.4+, then you have access to the "ms" function in function queries, and the standard, textbook approach to boosting by recency is:

recip(ms(NOW,startTime),3.16e-11,1,1)

ms gives the number of milliseconds between its two arguments. The expression as a whole boosts scores by 1 for docs dated now, by 1/2 for docs dated 1 year ago, by 1/3 for docs dated 2 years ago, etc.. (See http://wiki.apache.org/solr/FunctionQuery#Date_Boosting, as Sean Timm pointed out.)

In your case you have docs dated in the future, and those will get assigned a negative score by the above function, so you probably would want to throw in an absolute value, like this:

recip(abs(ms(NOW,startTime)),3.16e-11,1,1)

abs(ms(NOW,startTime)) will give the # of milliseconds between startTime and now, guaranteed to be nonnegative.

That would be a good starting place. If you want, you can then tweak the 3.16e-11 if it's too agressive or not agressive enough.

Tangentially, the ms function will only work on fields based on the TrieDate class, not the classic Date and LegacyDate classes. If your schema.xml was based on the example one for Solr 1.4, then your date field is probably already in the correct format.

查看更多
登录 后发表回答