我正在使用带有本地 Lucene 后端的休眠搜索(最新版本)。我有两个实体如下;
@Entity
@Indexed
public class A {
@Id
private Long id;
@FullTextField
private String text;
@KeywordField
private String keyword;
}
@Entity
public class B {
private BigDecimal number;
@OneToOne
@JoinColumn(name = "a_id")
private A a;
}
我有大量索引器,可以在应用程序启动时处理索引 A 实体。在搜索时,我希望搜索结果按实体 B的数字字段排序。
我的搜索功能是一个简单的布尔谓词,如下所示
.where(f -> f.bool()
.should(f.match().field("text").matching(query))
.should(f.match().field("keyword").matching(query.toUpperCase(Locale.ENGLISH)))
)
.fetch(offset, limit)
我应该怎么做才能根据另一个具有一对一关系的实体的另一个字段来排序/提升搜索结果?