mongodb
我有一个在and中不起作用的聚合spring boot
。如果有人可以帮助我,我将不胜感激。这是我的ExplainDoc
课:
@Document(collection = "ExplainDoc")
public class ExplainDoc{
@Id
private String id;
@TextIndexed(weight=3)
private String product_in_brief;
private Product product;
@TextScore
private Float textScore; }
这是我的另一堂课:
@Document(collection = "product")
public class Product{
@Id
private String id;
private String category;
}
我想做的是进行文本搜索并找到所有在其产品中具有ExplainDoc
给定文本的 s,product_in_brief
前提是他们的产品具有特定的类别。在我的搜索存储库中,我有一个如下聚合:
public List<MyAggrResults> searchBriefExplanations(String text, String category){
MatchOperation matchRegion = Aggregation.match(Criteria.where("product.category").is(category));
TextCriteria criteria = TextCriteria.forDefaultLanguage().matchingAny(text);
MatchOperation match = Aggregation.match(criteria);
GroupOperation group = Aggregation.group("product.category").push("$$ROOT").as("myresults").sum("textScore").as("score");
ProjectionOperation project = Aggregation.project("product_in_brief", "product").andExpression("{$meta: \"textScore\"}").as("textScore");
}
该代码现在有效。但是,我认为将product
对象始终作为嵌套文档非常昂贵。如果我想将product
对象用作 ,我应该如何更改代码@DBRef
?当我添加 时@DBRef
,代码不再起作用。我认为原因是product.category
不再被认可。
我希望有人能帮助我。