如何在MongoDB中设置文本搜索,以便在关键字最先出现的结果中获得更高的分数?
例如,我现在正在做的是:
db.product.aggregate(
[
{ $match: { $text: { $search: "notebook acer" }, isAvailable: true } },
{ $sort: { score: { $meta: "textScore" } } },
{ $project: { searchName: 1, _id: 0, score: { $meta: "textScore" } } }
]
)
在我得到的结果中:
{
"searchName" : "Mochila para Notebook Acer",
"score" : 1.25
},
{
"searchName" : "Notebook Acer E5-471-36me Intel Core I3 1.90ghz 4gb Hdd 500gb Linux Hdmi",
"score" : 1.0625
}
但我需要第二个结果排在第一位,因为关键字首先出现在索引字段中。
有没有办法做到这一点?