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

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

问题描述

我在数组键"上有一个索引,我用它为我的应用程序提供全文功能.

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

随着 2.4.3 的发布,我想使用text"索引类型.我在我的数组键"上投保了文本"索引类型,它似乎工作得非常快(比我旧的关键字全文方法快).

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).

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

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?

例如:

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

应该同时返回打印机和墨水的结果,而不是打印机或墨水的所有结果.

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

推荐答案

试试看:

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

另外,这里引用了 docs:

如果搜索字符串包含短语,则搜索执行 AND搜索字符串中的任何其他术语;例如搜索"闪烁twinkle" little star" 搜索 "twinkle twinkle" 和 ("little" 或明星").

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").

希望有所帮助.

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

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