我在数组“键”上有一个索引,我用它来为我的应用程序提供全文功能。
随着 2.4.3 的发布,我想使用“文本”索引类型。我在我的数组“键”上投保了“文本”索引类型,它似乎工作得非常快(比我的旧关键字全文方法快)。
问题是,我的应用假定字段是包容性的 (AND)。默认情况下,文本搜索 ORs 我的参数。
有谁知道以包容性方式运行文本搜索的方法?
例如:
db.supplies.runCommand("text", {search:"printer ink"})
应该返回带有打印机和墨水的结果,而不是带有打印机或墨水的所有结果。
最佳答案
试一试:
db.supplies.runCommand("text", {search:"\"printer\" \"ink\""})
另外,这里引用了 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").
希望对您有所帮助。
关于MongoDB 文本搜索和多个搜索词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16902674/