【发布时间】:2018-04-27 16:32:50
【问题描述】:
我正在尝试使用休眠搜索向实体添加全文搜索。我们的模式使用基于鉴别器的多租户,其中每个租户是一个带有 id 的park。模型如下所示:
@Entity
@Indexed
public class ProductModel {
@Field
// park is the tenant
private Long parkId;
@Field(index = Index.YES, analyze = Analyze.YES)
@Analyzer(definition = "customanalyzer")
private String name;
@Field(index = Index.YES, analyze = Analyze.YES)
@Analyzer(definition = "customanalyzer")
private String description;
}
在执行全文搜索时,我将始终基于parkId 进行过滤。用@Field注释parkId,然后像这样将该过滤器添加到lucene查询中是否有意义:
org.apache.lucene.search.Query luceneQuery = qb
.bool()
.must(qb.keyword().onFields("parkId").matching(parkIdFilter))
// any aditional queries, like on name, description
.must(qb.keyword().onFields(fields).matching(textQuery).createQuery())
.createQuery();
或者有没有更好的方法来使用带有鉴别器列的休眠搜索来处理多租户?我见过example mentioned in the docs,但不知道如何将其应用于我的特定用例。
【问题讨论】: