如何在 solr 中按实时分数排序?

How can I sort by realtime score in solr?

现在我有一个 solr 集合:问题

问题有一些字段:

id
answer_count
created_at
updated_at

现在我有了排序规则:

score = answer_count * 100 - (the hours now to created_at) * 5

然后我需要按分数排序。

分数是实时的,我该怎么做?

关键是函数查询。假设您使用 EDisMaxQP,您可以使用此值指定提升函数 (bf):

sub(product(answer_count,100),product(div(ms(NOW,created_at),3600000),5))

然而,函数查询会影响评分,但看起来您根本不想要任何评分,而是一个固定的排序顺序,所以我想这更像是将其用作 sort 值的情况:

sub(product(answer_count,100),product(div(ms(NOW,created_at),3600000),5)) desc

当然,提升较新的文档is in the FAQ,您可能会自己发现这一点。