MongoDB $text $search returns 确切的短语而不是包含
MongoDB $text $search returns exact phrase instead of contains
我的本地 MongoDB 上有此数据,我想在包含“the”的 title
字段上进行搜索。
当我使用这段代码时,它return编辑了一个空数组:
postsArray = await posts.find({ $text: { $search: "the" } }).toArray()
但是,如果我输入了准确的 title
,它 return 得到了正确的结果
postsArray = await posts.find({ $text: { $search: "the game" } }).toArray()
根据文档,第一个代码也应该return相同的结果,
知道为什么会这样吗?
谢谢
$text
搜索不会匹配the和and词,有一个关于匹配操作的说明:
The $text
operator ignores language-specific stop words, such as the and and in English.
让我们举一个不同单词的例子,它应该有效:
假设我们有以下文档:
{ "title": "Good Morning" }
查询 1: 搜索“好”字:
{ $text: { $search: "good" } }
Result: Playground
{ "title": "Good Morning" }
查询 2: 搜索“早上好”字词:
{ $text: { $search: "good morning" } }
Result: Playground
{ "title": "Good Morning" }
我的本地 MongoDB 上有此数据,我想在包含“the”的 title
字段上进行搜索。
当我使用这段代码时,它return编辑了一个空数组:
postsArray = await posts.find({ $text: { $search: "the" } }).toArray()
但是,如果我输入了准确的 title
,它 return 得到了正确的结果
postsArray = await posts.find({ $text: { $search: "the game" } }).toArray()
根据文档,第一个代码也应该return相同的结果,
知道为什么会这样吗?
谢谢
$text
搜索不会匹配the和and词,有一个关于匹配操作的说明:
The
$text
operator ignores language-specific stop words, such as the and and in English.
让我们举一个不同单词的例子,它应该有效:
假设我们有以下文档:
{ "title": "Good Morning" }
查询 1: 搜索“好”字:
{ $text: { $search: "good" } }
Result: Playground
{ "title": "Good Morning" }
查询 2: 搜索“早上好”字词:
{ $text: { $search: "good morning" } }
Result: Playground
{ "title": "Good Morning" }