【问题标题】:Is it possible to exclude/negate a phrase in mongo text search?是否可以在 mongodb 文本搜索中排除/否定一个短语?
【发布时间】: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


    【解决方案1】:

    好的,我必须回答这个问题:

    是的,有可能,但您必须至少有一个包含短语才能排除另一个短语。

    以下作品:

    db.words.find( { "$text": { "$search": "cake -\"cake sale\"" } },{_id: 0})
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-11
      • 1970-01-01
      • 2015-08-28
      • 2014-03-13
      • 2020-01-13
      • 1970-01-01
      • 2022-01-10
      • 1970-01-01
      相关资源
      最近更新 更多