【问题标题】:Mongodb atlas search: which analyzer is the best for searching multiple terms with AND conditionMongodb atlas search:哪个分析器最适合使用AND条件搜索多个术语
【发布时间】:2022-09-23 01:50:41
【问题描述】:

我正在尝试构建 MongoDB Atlas 全文搜索索引。但是,我对分析仪有点挣扎。

这是我的索引:

{
  \"analyzer\": \"lucene.standard\",
  \"searchAnalyzer\": \"lucene.standard\",
  \"mappings\": {
    \"dynamic\": false,
    \"fields\": {
      \"description\": {
        \"type\": \"string\"
      }
    }
  }
}

我的问题是当我对“描述”字段执行搜索时。

这是我执行搜索的方式:

{
  index: \'description_index\',
  text: {
    query: \'chicken alfredo\',
    path: \'description\'
  }
}

这将返回描述字段中存在 \"chicken\" 或 \"alfredo\" 或两者兼有的文档。但我需要它返回描述字段中同时存在“鸡”和“阿尔弗雷多”的文档。请注意,描述字段中的字符串可以包含其他词,例如“Roasted Chicken Alfredo with Chips”。在这个例子中,我想要的解决方案应该返回“Roasted Chicken Alfredo with Chips”文档,而不是带有以下描述“Chicken Roberto”的文档。

有什么想法可以解决这个问题吗?

  • 我不认为分析仪需要改变。我添加了一个可以解决您的问题的查询替代方案。

标签: mongodb mongodb-atlas mongodb-atlas-search


【解决方案1】:

尝试使用 phrase 运算符,这会将您的查询更改为:

{
   index: 'description_index',
   phrase: {
     query: 'chicken alfredo',
     path: 'description'
   }
 }

【讨论】:

    猜你喜欢
    • 2021-02-02
    • 1970-01-01
    • 2022-12-15
    • 2021-06-01
    • 2022-06-14
    • 2022-06-13
    • 2021-12-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多