【发布时间】:2017-07-05 21:39:07
【问题描述】:
我有以下 2 个带有休眠和休眠搜索注释的类:
父类:
@Indexed
@Entity
public class Parent {
@Id
@Column(name="parent_id")
private Long id;
@Field(store = Store.YES)
private String name;
@IndexedEmbedded
@OneToMany(fetch = FetchType.LAZY, mappedBy = "parent", targetEntity = Child.class)
private List<Child> childList;
//getters and setters
}
儿童班:
@Entity
public class Child {
@Id
private Long id;
@ManyToOne(targetEntity = Parent.class)
@ContainedIn
@JoinColumn(name = "parent_id")
private Parent parent;
@Field(store = Store.YES)
private String name;
}
我为上述场景创建了一个索引。现在我正在尝试通过搜索给定的父名称来获取所有子名称。
我在场地上使用投影如下:
Query searchQuery = queryBuilder.keyword().onField("name").matching("test").createQuery();
FullTextQuery fullTextQuery = fullTextEntityManager.createFullTextQuery(searchQuery, Parent.class);
fullTextQuery.setProjection("childList.name");
现在,当我尝试运行查询以检索搜索结果时,我得到了父模型的唯一第一个子模型的名称。
当我使用 Luke 查看索引时,我可以看到文档中的所有值。
如何获取索引中存储的所有子名称的列表?
【问题讨论】:
标签: java hibernate lucene hibernate-search