mongoDB前缀通配符:全文搜索($ text)查找带有搜索字符串的部分 [英] mongoDB prefix wildcard: fulltext-search ($text) find part with search-string
问题描述
我的mongodb带有$text-Index
和类似这样的元素:
I have mongodb with a $text-Index
and elements like this:
{
foo: "my super cool item"
}
{
foo: "your not so cool item"
}
如果我确实使用
mycoll.find({ $text: { $search: "super"} })
我得到第一项(正确).
i get the first item (correct).
但是我也想搜索"uper"来获得拳头物品-但是如果我尝试:
But i also want to search with "uper" to get the fist item - but if i try:
mycoll.find({ $text: { $search: "uper"} })
我没有得到任何结果.
我的问题:
如果有一种使用$ text的方法,那么它可以使用一部分搜索字符串来查找结果? (例如mysql
中的'%uper%'
)
My Question:
If there is a way to use $text so its finds results with a part of the searching string? (e.g. like '%uper%'
in mysql
)
注意:我不要求进行正则表达式搜索-我要求在$ text-search中进行正则表达式搜索!
推荐答案
使用$text
运算符无法做到这一点.
It's not posible to do it with $text
operator.
使用包含在字符串值或字符串数组中的术语创建文本索引,并且搜索基于这些idexes.
Text indexes are created with the terms included in the string value or in a strings array and the search is based in those idexes.
您只能将词项归为一个词组,而不能参与其中.
You can only group terms on a pharse but not take part of them.
阅读 $text
运营商参考和
查看全文