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

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

问题描述

我有一个 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.

谁能告诉我怎么做?

谢谢

推荐答案

如果您使用的是 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,等等.(参见 http://wiki.apache.org/solr/FunctionQuery#Date_Boosting,正如 Sean Timm 指出的那样.)

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 和 now 之间的毫秒数,保证为非负数.

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 - 提升功能(bf)以增加日期最接近现在的文档的分数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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