Mongo Db按索引字段搜索 [英] Mongo Db search by indexed field

查看:63
本文介绍了Mongo Db按索引字段搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将字段"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?

推荐答案

来自MongoDB

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆