Hibernate Search不适用于多对多的关系

时间:2015-07-23 04:34:32

标签: hibernate lucene hibernate-search

我有两个实体RestaurantCategory,通过多对多关系相关联。我想通过category_name搜索餐馆,但我无法获得正确的搜索结果,即使我可以看到该列表正在使用数据正确填充。实体是:

@Entity
@Table(name = "restaurant")
@Indexed
public class Restaurant implements Comparable<Restaurant> {
    @ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
    @JoinTable(name = "restaurant_category", joinColumns = { @JoinColumn(name = "restaurant_id", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "category_id", nullable = false, updatable = false) })
    @IndexedEmbedded
    private List<Category> listOfCategories;
}

这是类别实体

 @Entity
 @Table(name = "category")
 @Indexed
 public class Category {

 @Column(name = "category_name")
 @Field(index = Index.YES, analyze = Analyze.YES, store = Store.NO)
 private String categoryName;

这是我的搜索查询

Query query = queryBuilder.keyword()
            .onFields("listOfCategories.categoryName").matching("Pub")
            .createQuery();


    org.hibernate.Query hibernateQuery = fullTextSession
            .createFullTextQuery(query, Restaurant.class);

    List<Restaurant> searchResults = hibernateQuery.list();

提前致谢!

0 个答案:

没有答案