MongoDB文本搜索和多个搜索词 [英] MongoDB Text Search AND multiple search words

查看:113
本文介绍了MongoDB文本搜索和多个搜索词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数组键的索引,用于向我的应用程序提供全文功能。



随着2.4.3的发布,I '喜欢利用文本索引类型。我确保了我的数组键上的文本索引类型,并且它似乎可以快速工作(比我的旧关键字全文方法更快)。



问题是,我的应用程序假定字段包含(AND)。默认情况下,文本搜索ORs我的参数。



有谁知道运行文本搜索的方式吗?



例如:

  db.supplies.runCommand(text,{search:printer ink})

应使用打印机和墨水返回结果,而不是使用打印机或墨水的所有结果。

解决方案

试试看:

  db.supplies.runCommand(text,{search:\printer \\ink \})

另外,以下是来自文档
$ b


如果搜索字符串包含短语,搜索将执行与
的AND操作,搜索字符串;例如搜索\闪烁
闪烁\小星星搜索闪烁闪烁和(小或
星星)。



希望有帮助。


I have an index on an array "keys" that I am using to provide full text functionality to my applicaiton.

With the release of 2.4.3, I'd like to utilize the "text" index type. I insured a "text" index type on my array "keys" and it seems to work SUPER fast (faster than my old keywords full text method).

The problem is, my app assumes that fields are inclusive (AND). By default, the text search ORs my parameters.

Does anyone know of a way to run a text search inclusively?

For example:

db.supplies.runCommand("text", {search:"printer ink"})

should return results with both printer and ink, instead of all results with either printer or ink.

解决方案

Give a try to:

db.supplies.runCommand("text", {search:"\"printer\" \"ink\""})

Also, here's a quote from docs:

If the search string includes phrases, the search performs an AND with any other terms in the search string; e.g. search for "\"twinkle twinkle\" little star" searches for "twinkle twinkle" and ("little" or "star").

Hope that helps.

这篇关于MongoDB文本搜索和多个搜索词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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