MongoDB中的全文本搜索未针对"@@@"产生预期结果 [英] Full Text Search in MongoDB not yielding the expected result for "@@@"
问题描述
因此,我在一个集合中有一个文档,其中的一个字段的值为"@@@" 我索引了集合并尝试运行查询:
So I have a document in a collection with on of the fields having a value "@@@" I indexed the collection and tried running the query:
db.getCollection('TestCollection').find({$text:{$search:"\"@@@\""}})
但是它没有显示结果
我该如何解决?
示例文档:
{
"_id" : ObjectId("5b90dc6d3de8562a6ef7c409"),
"field" : "value",
"field2" : "@@@"
}
推荐答案
文本搜索旨在基于令牌化(将字符串转换为单独的术语(感兴趣的),然后摘录(将每个术语转换为用于索引的根形式)根据特定于语言的规则.
Text search is designed to index strings based on language heuristics. Text indexing involves two general steps: tokenizing (converting a string into individual terms of interest) followed by stemming (converting each term into a root form for indexing based on language-specific rules).
在标记化步骤中,某些字符(例如,标点符号,例如@
)被分类为单词分隔符(又称为定界符),而不是文本输入,并且被用于将原始字符串分成术语.特定于语言的停用词(常见的词有"the","is"或英文"中的"on"也排除在文本索引之外.
During the tokenizing step certain characters (for example, punctuation symbols such as @
) are classified as word separators (aka delimiters) rather than text input and used to separate the original string into terms. Language-specific stop words (common words such as "the", "is", or "on" in English) are also excluded from a text index.
由于您的@@@
搜索短语完全由定界符组成,因此文本索引中没有相应的条目.
Since your search phrase of @@@
consists entirely of delimiters, there is no corresponding entry in the text index.
如果要匹配通用字符串模式,则应使用正则表达式而不是文本搜索.例如:db.getCollection('TestCollection').find({field2:/@@@/})
.但是,请注意索引用法用于正则表达式.
If you want to match generic string patterns, you should use regular expressions rather than text search. For example: db.getCollection('TestCollection').find({field2:/@@@/})
. However, please note the caveats on index usage for regular expressions.
这篇关于MongoDB中的全文本搜索未针对"@@@"产生预期结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!