评分算法是MongoDB内部的,可能会随着时间的推移而变化,因此精确的值应该无关紧要。您可以通过查看
sources
最终分数取决于搜索词(或词干)的出现次数、匹配之间的距离、匹配质量(完全匹配与部分匹配)、语言设置和权重
configure
. 这些都是很重要的东西,很难记录下来。然而,有一篇博客文章很好地解释了一些方面:
https://blog.codecentric.de/en/2013/01/text-search-mongodb-stemming/
最后,如果你想知道是否有一个完美的匹配,我能想到的唯一方法是这样做:
db.getCollection('test').aggregate(
{
// do the normal filtering query
$match: {
$text: {
$search: "mitsubishi lancer 2011"
}
}
}, {
// select what's relevant in the output and add an indicator "perfectmatch"
$project: {
"text": 1,
"score": {
$meta: "textScore"
},
"perfectmatch": {
$cond: [
{ $eq: [ "$text", "mitsubishi lancer 2011" ] }, // this would check for a perfect match using the exact full string, for individual token matching you would need to do tokenize your query and do a series of other checks here.
true,
false
]
}
}
}, {
// if you want to have the results sorted by "best match first"
$sort: {
"score": -1
}
})