MongoDB:按TextScore和其他价值的产品排序

发布于 2025-01-26 14:56:17 字数 552 浏览 2 评论 0原文

是否可以使用将{$ META:“ textscore”}与其他一些值结合的投影对文本搜索结果进行排序?我们的每个文档都有质量(Pagerank)分数,我想使用文本匹配和Pagerank的产品对文档进行分类:

var cursor = packages.find(query).project({
    score: {$multiply: [{$meta: "textScore"}, '$_pagerank']},
    Foo: 1, 
    Bar:1,
}).sort({score:-1}).limit(limit);

上述查询的结果确实包含了预期的分数值,但根本不排序输出。我测试了排序仅基于textScore .sort({score:{$ meta:“ text -score”}}),但这并不考虑文档的pagerank。

是否有可能使用投影值在MongoDB中进行排序?我们目前正在使用MongoDB 4.4。

Is it possible to sort text-search results using a projection that combines {$meta: "textScore"} with some other values? Each of our documents has a quality (pagerank) score, and I would like to sort results using the product of the text-match and the pagerank for the document:

var cursor = packages.find(query).project({
    score: {$multiply: [{$meta: "textScore"}, '$_pagerank']},
    Foo: 1, 
    Bar:1,
}).sort({score:-1}).limit(limit);

The results for the above query do contain the expected score values, but the output is not sorted at all. I tested that sorting does work based on only the textScore .sort({score:{$meta:"textScore"}}) however that does not take the pagerank of the document into account.

Is it possible at all to sort in mongodb using a projected value? We are currently using mongodb 4.4.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文