如何在休眠搜索中索引字符串列表

How to index list of strings in hibernate search

如何在 Hibernate 搜索中索引字符串列表?

我试过这样

@Field(index = Index.YES, analyze = Analyze.NO, store = Store.YES, analyzer = @Analyzer(definition = "customanalyzer_query"))
@ElementCollection(fetch = FetchType.EAGER)
private Set<String> hashedTagList;

我在提交新对象时遇到错误。

我正在使用 Hibernate ogmmongodb

您可以使用@IndexedEmbedded 对元素集合进行索引。这将是做你想做的最简单的方法:

@Field(analyze = Analyze.NO, store = Store.YES)
@IndexedEmbedded
private Set<String> keywords = new HashSet<String>();

请注意,必须使用 Set,以便明确定义包含元素的类型。

这是一种解决方法,我们计划在即将推出的 Search 6 中以更简洁的方式解决该问题。

您还可以使用@FieldBridge 对数据进行反规范化。关于使用 Set 的评论仍然有效。

你可以在这里找到我们在我之前的工作中使用的@FieldBridge 正是为了这个目的:https://github.com/openwide-java/owsi-core-parent/blob/master/owsi-core/owsi-core-components/owsi-core-component-jpa/src/main/java/fr/openwide/core/jpa/search/bridge/StringCollectionFieldBridge.java .

顺便说一下,您定义了一个分析器,但将分析器设置为 Analyze.NO,因此您的分析器将不会被使用。