我的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运营商参考和文本索引说明.
更多推荐
mongoDB前缀通配符:全文搜索($ text)查找带有搜索字符串的部分
发布评论