SOLR-Boost函数(bf)增加日期最接近NOW的文档的分数 [英] SOLR - Boost function (bf) to increase score of documents whose date is closest to NOW

查看:193
本文介绍了SOLR-Boost函数(bf)增加日期最接近NOW的文档的分数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Solr实例,其中包含文档,文档的'startTime'字段范围从上个月到现在的一年.我想添加一个增强查询/函数来增强其startTime字段接近当前时间的文档的分数.

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.

到目前为止,我已经看到了很多使用rord为新文档添加增强功能的示例,但是我从未见过这样的示例.

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?

谢谢

推荐答案

如果您使用的是Solr 1.4+,则可以访问函数查询中的"ms"函数,以及可以提高新近度的标准教科书方法是:

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给出两个参数之间的毫秒数.总体而言,该表达式将现在日期的文档的得分提高1,将1年前的文档的得分提高1/2,将2年前的文档的得分提高1/3,依此类推.(请参阅

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))将给出startTime和现在之间的毫秒数,并保证该值是非负数.

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

那将是一个很好的起点.如果需要,可以调整3.16e-11的攻击性或攻击性.

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.

可能,ms函数仅适用于基于TrieDate类的字段,不适用于经典的Date和LegacyDate类.如果您的schema.xml基于Solr 1.4的示例,那么您的日期字段可能已经采用了正确的格式.

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.

这篇关于SOLR-Boost函数(bf)增加日期最接近NOW的文档的分数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆