我需要在名为blog的集合中搜索文档,该集合具有为标题,标签,摘要和正文定义的文本索引:
@Document(collection="blog")
public class Blog {
@Id
private String id;
@TextIndexed(weight = 10)
private String title;
@TextIndexed(weight = 9)
private String tags;
@TextIndexed(weight = 8)
private String summary;
@TextIndexed(weight = 7)
private String body;
@TextScore
private Float score;
//getters and setters
}
现在,我需要根据以下条件对blog集合进行文本搜索:
对于第二种情况TextCriteria定义如下:
TextCriteria criteria = TextCriteria.forDefaultLanguage().matching("SingleWord");
对于第三种情况,如何在单个查询中编写组合的条件定义:
query 1: db.articles.find( { $text: { $search: "\"coffee cake\"" } } ) //phrase search
query 2: db.articles.find( { $text: { $search: "coffee cake" } } ) //word search
我可以用]执行搜索>
query 1 OR query 2 with sorted result based on score.
对于完整短语匹配的结果,分数应该更高。
我需要在名为blog的集合中搜索文档,该文档具有为标题,标签,摘要和正文定义的文本索引:@Document(collection =“ blog”)公共类Blog {@Id私有字符串...
Spring Data MongoDB支持以下用于文本搜索的操作: