【问题标题】:Spring Data MongoDB with text index: difference between matchingany and matchingphraseSpring Data MongoDB with text index:matchingany和matchingphrase之间的区别
【发布时间】:2017-11-24 04:53:54
【问题描述】:

我正在为一个应用程序使用 MongoDB 和 Spring

我正在我的收藏中使用文本索引。

我找到了两种方法:

  • matchingany
  • matchingphrase

但我无法理解其中的区别。

请帮助我理解它们。

【问题讨论】:

    标签: spring mongodb spring-data-mongodb full-text-indexing


    【解决方案1】:

    如果你想匹配多个单词组成一个短语,那么使用matchingPhrase,如果你想匹配一组单词中的至少一个单词,那么使用matchingAny

    例如,给定这些文档(并假设 title 属性是文本索引的):

    { "id": 1, "title": "The days of the week"}
    { "id": 2, "title": "Once a week"}
    { "id": 3, "title": "Once a month"}
    
    • matchingAny("Once") 将匹配 id=2 和 id=3 的文档
    • matchingAny("month", "foo' , "bar") 将匹配 id=3 的文档
    • matchingPhrase("The days of the week") 将匹配 id=1 的文档

    更多详情in the docs.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-31
      • 2016-09-12
      • 1970-01-01
      相关资源
      最近更新 更多