如何解决MongoDB $text $search 返回精确短语而不是包含
我在本地 MongoDB 上有这些数据,我想搜索包含“the”的 title
字段。
postsArray = await posts.find({ $text: { $search: "the" } }).toArray()
但是,如果我输入了确切的 title
,它会返回正确的结果
postsArray = await posts.find({ $text: { $search: "the game" } }).toArray()
知道为什么会这样吗?
谢谢
解决方法
$text
搜索不会匹配the 和and 词,有关于匹配操作的说明:
$text
运算符会忽略特定于语言的停用词,例如英语中的 the 和 and。
让我们举一个不同单词的例子,它应该可以工作:
假设我们有以下文档:
{ "title": "Good Morning" }
查询 1: 搜索“好”字:
{ $text: { $search: "good" } }
结果: Playground
{ "title": "Good Morning" }
查询 2: 搜索“早上好”字样:
{ $text: { $search: "good morning" } }
结果: Playground
{ "title": "Good Morning" }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。