gpt4 book ai didi

java - Hibernate Search 未正确索引嵌入式集合

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:16:32 27 4
gpt4 key购买 nike

我目前正在从事一个涉及使用 Hibernate Search 的项目。目前该项目使用纯 SQL 进行搜索,我们想改用文本搜索(需要知道并正确拼写第一个单词会很烦人)。

架构是一个产品可以有多个版本,当前版本包含产品的名称。

Public Class Product extends ProgEntity
{
private List<ProductVersion> versions = new ArrayList<ProductVersion>();
...
}

Public Class ProductVersion extends ProgEntity
{
String productName;
...
}

我需要能够根据产品名称搜索产品。我能够通过 productName 对 ProductVersions 进行索引,但问题不大,但索引 Product 被证明是一个更大的问题。

经过一些研究,这就是我所拥有的,但是当我将产品更新到数据库时,没有创建索引。

@Entity
@Indexed
Public Class Product extends ProgEntity
{
@IndexedEmbedded
private List<ProductVersion> versions = new ArrayList<ProductVersion>();
...
}

@Entity
@Embeddable
Public Class ProductVersion extends ProgEntity
{
@Field
String productName;
...
}

DocumentID 是 ProgEntity 的一部分。我需要确保如果我更新产品或产品版本,它将被正确索引,这似乎现在没有发生。

对我做错了什么有什么建议吗?

最佳答案

在您发布的代码中映射的 Product 和 ProductVersion 之间没有关系(例如多对一、多对一)。这种关系必须是双向的。使用@IndexedEmbedded 注释Product 的collection 字段,使用@ContainedIn 注释ProductVersion 端的反向字段,您应该已准备就绪。

关于java - Hibernate Search 未正确索引嵌入式集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6446695/

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