mongoDB 前缀通配符:全文搜索 ($text) 使用搜索字符串查找部分 [英] mongoDB prefix wildcard: fulltext-search ($text) find part with search-string

查看:88
本文介绍了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) 使用搜索字符串查找部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆