按 Instant 范围分面休眠搜索结果失败

Faceting hibernate search results by Instant range fails

我有一个索引创建时间戳为 java.time.Instant 类型的实体,我想按创建时间戳范围对搜索结果进行分类。
该实体看起来如下所示:

@Entity
@Indexed
public class Document {

    @Id
    @DocumentId
    private Long id;

    @Field
    private String name;

    @Field(analyze = Analyze.NO)
    @Facet
    private Instant creationTimestamp;
}

当我启动我的应用程序时,出现以下错误:

org.hibernate.search.exception.SearchException: HSEARCH000264: @Facet is not supported for type 'java.time.Instant'. See org.hibernate.search.bugs.Document#creationTimestamp

我在 hibernate documentation.

中没有发现任何与即时值分面相关的内容

是否可以通过创建时间戳范围对休眠搜索结果进行分类?

我在这里创建了一个失败的测试用例:github repo link

恐怕 Java 8 date/time 类型在 Hibernate 搜索分面子系统中尚不支持。我创建了一张票来解决这个问题,但我不能说我们什么时候会(有内部并发症):https://hibernate.atlassian.net/browse/HSEARCH-2954

更新:在 Hibernate Search 6 中支持 date/time 类型的 Facet 与聚合,它取代了 Hibernate Search 5 facet。 Getting started with Hibernate Search 6, Aggregations in Hibernate Search 6.

同时,您可以使用代表时间戳的 @Transient 长字段来解决这种缺乏支持的问题:

@Entity
@Indexed
public class Document {

    @Id
    @DocumentId
    private Long id;

    @Field
    private String name;

    private Instant creationTimestamp;

    @Field(analyze = Analyze.NO)
    @Facet
    @javax.persistence.Transient
    public Long getCreationForFaceting() {
        return creationTimestamp == null ? null : creationTimestamp.toEpochMilli();
    }
}

然后也使用长时间戳进行查询。

从长远来看这不是一个理想的解决方案,但这是我能想到的唯一解决方案。