gpt4 book ai didi

java - 按 Instant 范围分面 hibernate 搜索结果失败

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:48:52 24 4
gpt4 key购买 nike

我有一个索引创建时间戳为 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 中找到任何与即时值分面相关的信息.

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

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

最佳答案

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

更新:Hibernate Search 6 支持日期/时间类型方面的聚合,取代了 Hibernate Search 5 方面。 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();
}
}

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

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

关于java - 按 Instant 范围分面 hibernate 搜索结果失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47224259/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com