Mongo Db按索引字段搜索 [英] Mongo Db search by indexed field
问题描述
我将字段"search_string"添加到我的文档中并为其建立索引. db.my_collection.createIndex({search_string: "text"})
Search_string包含以下内容:一个竞技场竞技场".
I add field 'search_string' to my document and index it. db.my_collection.createIndex({search_string: "text"})
Search_string contains this: 'a ar are aren arena'.
我可以找到记录:db.my_collection.find({$text: {$search: 'ar'}})
,db.my_collection.find({$text: {$search: 'аren'}})
,db.my_collection.find({$text: {$search: 'arenа'}})
,但是db.my_collection.find({$text: {$search: 'а'}})
和db.my_collection.find({$text: {$search: 'аre'}})
不返回任何内容.为什么会发生?
I can find record with this: db.my_collection.find({$text: {$search: 'ar'}})
, db.my_collection.find({$text: {$search: 'аren'}})
, db.my_collection.find({$text: {$search: 'arenа'}})
, but db.my_collection.find({$text: {$search: 'а'}})
and db.my_collection.find({$text: {$search: 'аre'}})
returns nothing. Why does it happens?
推荐答案
From the MongoDB manual
匹配操作
停词
$ text运算符会忽略特定于语言的停用词,例如and和英语.
The $text operator ignores language-specific stop words, such as the and and in English.
"a"和"are"都在默认英语停用词列表中,因此将被忽略.谷歌快速搜索英语停用词将找到大量包含完整列表的页面.
Both "a" and "are" are in the list of default English language stopwords so will be ignored. A quick google search for English language stopwords will find plenty of pages with the full list.
这篇关于Mongo Db按索引字段搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!