gpt4 book ai didi

java - 使用 hibernate 按 userId 字段过滤全文搜索结果

转载 作者:搜寻专家 更新时间:2023-10-31 20:27:39 24 4
gpt4 key购买 nike

假设我有 2 个注释实体用于全文搜索:

@Entity
public class User implements Serializable {

@Id
public Long id;
...

}

@Entity
@Indexed
public class Post {

@Id
public Long id;

@Field(name = "content")
public String content;

@ManyToOne
public User user;

...

}

很简单write full text search on just content field .但是如何通过文本关键字和用户 ID 过滤结果呢?例如,在内容字段和 user.id 等于 10 时搜索“hello”的查询?

最佳答案

您要查找的关键字是注释 IndexedEmbedded。

@ManyToOne
@org.hibernate.search.annotations.IndexedEmbedded(includePaths={ "userId" })
public User user;

如果您现在创建 LuceneIndex,您的 LuceneDocument 中将有一个名为 User.userId 的新字段。您现在可以搜索 UserId(作为字符串)和组合的内容。请查看 Luke 以检查您的索引文件。

关于java - 使用 hibernate 按 userId 字段过滤全文搜索结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29045145/

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