【问题标题】:How to assign score on matching results in MongoDB如何在 MongoDB 中为匹配结果分配分数
【发布时间】:2018-04-17 03:46:22
【问题描述】:

我有以下 MongoDB 文档,我想在全文搜索中匹配每个属性时分配分数

  @Document
public class User {
    // there would be multiple industries and few or all could match, if any of the substring matched score is 40
    private String industries;
    // if there is any matching substring score is 10
    private String regions;
    // score is 20 on any match
    private String cities;
}

在聚合阶段,如果是特定匹配,我可以检查计数并分配分数,但在全文搜索中,我如何知道哪些字段匹配?并为他们分配相关分数?

【问题讨论】:

    标签: java mongodb search spring-data


    【解决方案1】:

    您不会知道哪些字段匹配,但您可以根据分配给字段的权重获得排序结果。在集合上创建索引时,您可以为集合中的不同字段分配权重并使用排序或投影。

    https://docs.mongodb.com/manual/tutorial/control-results-of-text-search/

    【讨论】:

    • 权重和分数以不同的方式工作,如果您为行业分配权重 40,并且如果整个字符串匹配,则分数将是 200 或超过 40,我在这里寻找的是分配在任何比赛中得分不超过 40,因此最高得分应为 40
    • 在此处回答 stackoverflow.com/questions/23242769/… 看起来更相关,但这是针对不基于全文搜索的特定键
    猜你喜欢
    • 1970-01-01
    • 2021-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多