我有两个实体Restaurant
和Category
,通过多对多关系相关联。我想通过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();
提前致谢!