spring Data JPA 集成solr7(九)

4.17. Nested Documents

Nested Documents provides the ability to add documents inside of other documents in a parent/child relationship.

The nested documents need to be indexed along with the parent one and cannot be updated individually. Though nested documents will appear as individual ones in the index. Resolving the parent child relation is done at query query time.

To indicate a property should be treated as nested object it has to be annotated with either @o.a.s.c.solrj.beans.Field(child=true) or @o.s.d.s.core.mapping.ChildDocument.

public class Book {

    @Id String id;
    @Indexed("type_s") String type;
    @Indexed("title_t") String title;
    @Indexed("author_s") String author;
    @Indexed("publisher_s") String publisher;

    @ChildDocument List<Review> reviews;      

    // setters and getters ...

}

public class Review {

    @Id String id;                            
    @Indexed("type_s") String type;
    @Indexed("review_dt") Date date;
    @Indexed("stars_i") int stars;
    @Indexed("author_s") String author;
    @Indexed("comment_t") String comment;

}
Multiple child documents can be associated with a prarent one, or just use the domain type to store a single relation ship.
Note that the nested document also needs to have an unique id assigned.

Assuming Book#type is book, and Review#type resolves to review retrieving Book with its child relations reviews can be done by altering the fl query parameter.

Query query = new SimpleQuery(where("id").is("theWayOfKings"));
query.addProjectionOnField(new SimpleField("*"));
query.addProjectionOnField(new SimpleField("[child parentFilter=type_s:book]")); 

return solrTemplate.queryForObject("books", query, Book.class);
The parent filter always defines the complete set of parent documents in the index, not the one for a single document.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值