Hibernate搜索,查询关联

时间:2016-01-05 10:14:32

标签: hibernate-search

我是Hibernate搜索新手,有人可以建议我如何查询嵌入式实体(一对多)

@Indexed
@Entity
public class EventDetails implements Serializable 
{
    @OneToMany( cascade = CascadeType.ALL )
    @IndexedEmbedded
    @JoinColumn( name = "event_id" )
    private Set<Batches> batches;

    --setter and getter--
}

@Entity
@Indexed
public class Batches 
{
    @Column( name = "batch" )
    private String batch;

    @ManyToOne
    @ContainedIn(mappedBy="batches")
    private EventDetails eventDetails;

    --setter and getter--
}

服务类

public List<EventDetails> search()
{
fullTextEntityManager = org.hibernate.search.jpa.Search.getFullTextEntityManager(getEntityManager());
    QueryBuilder q = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(EventDetails.class).get();
    org.apache.lucene.search.Query luceneQuery = q.keyword().wildcard().onField("").matching(text).createQuery();
    javax.persistence.Query jpaQuery = fullTextEntityManager.createFullTextQuery(luceneQuery, EventDetails.class);
    List<EventDetails> list = jpaQuery.getResultList();
 return list;
}

现在如果我必须在批处理表中对“批处理”属性实现全文查询,我应该将什么作为参数传递给我的服务中的“onField()”方法?

谢谢!

1 个答案:

答案 0 :(得分:1)

请使用window.history.replaceState(stateObj, title, url); 。您还必须使用batches.batch注释对batch字段编制索引。

另请参阅hibernate搜索文档herehere

您始终可以使用luke查看和查询索引中的字段。