mongoDB前缀通配符:全文搜索($ text)查找带有搜索字符串的部分

编程入门 行业动态 更新时间:2024-10-26 02:25:01
本文介绍了mongoDB前缀通配符:全文搜索($ text)查找带有搜索字符串的部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的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)查找带有搜索字符串的部分

本文发布于:2023-10-18 23:47:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1505778.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:通配符   前缀   字符串   全文   mongoDB

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!