Spring 带有文本索引的数据 MongoDB:matchingany 和 matchingphrase 之间的区别

Spring Data MongoDB with text index: difference between matchingany and matchingphrase

我正在使用 MongoDB 和 Spring 申请

我在 collection 上使用文本索引。

我找到了两个方法:

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

请帮助我理解它们。

如果你想匹配多个单词组成的短语,那么使用 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