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

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

我有一个带有 $text-Index 和如下元素的 mongodb:

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 possible to do it with $text operator.

文本索引是用包含在字符串值或字符串数​​组中的术语创建的,搜索基于这些索引.

Text indexes are created with the terms included in the string value or in an array of strings and the search is based in those indices.

您只能对短语中的术语进行分组,但不能参与其中.

You can only group terms on a phrase but not take part of them.

阅读$text 操作员参考 和 文本索引描述.

更多推荐

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

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

发布评论

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

>www.elefans.com

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