【发布时间】:2019-04-27 17:01:55
【问题描述】:
与How to AND and NOT in MongoDB $text search相关
以同文档词集合为例:
{ "text" : "cake" }
{ "text" : "sale" }
{ "text" : "sale cake" }
{ "text" : "cake sale" }
{ "text" : "dress sale" }
{ "text" : "cake sale monday" }
是否有可能以某种方式明确否定搜索短语(不仅仅是一个词),引用短语时以下内容不起作用:
db.words.find( { "$text": { "$search": "-\"cake sale\"" } },{_id: 0})
注意减号(否定的尝试)"-\"cake sale\"" 是为了从结果集中排除包含精确短语的文档。
我可以处理这个问题的唯一方法是通过使用$regex 从文本搜索步骤中排除已经检索到的结果来进一步聚合。
【问题讨论】:
标签: mongodb