我想知道如何使用固定值限制休眠搜索查询,例如,如果我正在对电子商店进行自由文本搜索,他们在 URL 中有一个值,将结果限制为仅限计算机。或者另一个示例可以是基于位置进行搜索。
当前代码
@Entity
@Indexed
public class Store {
@Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO)
private String name;
@IndexedEmbedded
@OneToMany(mappedBy = "computer", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Computer> computers;
}
@Entity
public class Computer {
@Field
private String name;
@ContainedIn
@ManyToOne
@JoinColumn(name = "store_id", nullable = false)
private Store Store;
}
关键字搜索查询
FullTextSession fullTextSession = Search.getFullTextSession(sessionManager.getSession());
QueryBuilder queryBuilder = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(Store.class).get();
Query luceneQuery = queryBuilder.keyword().onFields("name").andField("computers.name").matching(keyword).createQuery();
org.hibernate.search.FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery(luceneQuery, Computer.class);
有人知道我缺少什么才能让它工作吗?