是否可以在 solr 中指定文档的顺序 [英] Is it possible in solr to specify an ordering of documents

查看:28
本文介绍了是否可以在 solr 中指定文档的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不是通用的排序字段,而是说我想按该顺序返回的文档 ID 列表.

Not a generic sort field, but say a list of document IDs I want returned in that order.

示例:文档 ID = [5, 3, 10, 6]

Example: document_ids = [5, 3, 10, 6]

我可以按照文档 5、3、10、6 的顺序查询 solr 吗?

Can I query solr for documents 5, 3, 10, 6 in that order?

推荐答案

使用 Boost Query

您可以为此使用 bq 参数(Boost Query),然后按分数排序,这是默认设置.

Using Boost Query

You can use the bq param (Boost Query) for this and then sort by score, which is default.

q=id:5+OR+id:3+OR+id:10+OR+id:6&bq=id:5^4+id:3^3+id:10^2

正如您在 bq 参数中所见,每个 ID 的提升值都在下降,直到最后一个(在您的情况下为 6)不再获得任何提升.由于您按 ID 进行搜索,因此每个文档都将具有相同的分数,因此以这种方式提升它们将使您获得所需的排序顺序.

As you can see within the bq parameter each of the IDs gets a declining boost value, until the last one - in your case 6 - does not receive any boost any more. Since you search by ID, each document would have the same score, so boosting them that way will get you the sort order you want.

关于参数的一些参考

如果您使用的是标准请求处理程序或 (e)DisMax,这在任何情况下都有效

In case you are using the Standard Request Handler or the (e)DisMax this works in any case

q=id:5^4+OR+id:3^3+OR+id:10^2+OR+id:6

这使用了术语提升,在 中有解释参考文档在主题Boosting a Term with ^下方.逻辑和上面一样.

This makes use of Term Boosting, which is explained in the reference documentation below the topic Boosting a Term with ^. The logic keeps the same as above.

这篇关于是否可以在 solr 中指定文档的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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