【发布时间】:2017-11-24 04:53:54
【问题描述】:
我正在为一个应用程序使用 MongoDB 和 Spring
我正在我的收藏中使用文本索引。
我找到了两种方法:
-
matchingany matchingphrase
但我无法理解其中的区别。
请帮助我理解它们。
【问题讨论】:
标签: spring mongodb spring-data-mongodb full-text-indexing
我正在为一个应用程序使用 MongoDB 和 Spring
我正在我的收藏中使用文本索引。
我找到了两种方法:
matchingany
matchingphrase但我无法理解其中的区别。
请帮助我理解它们。
【问题讨论】:
标签: spring mongodb spring-data-mongodb full-text-indexing
如果你想匹配多个单词组成一个短语,那么使用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.
【讨论】: