数组的@Field注释

时间:2018-01-16 15:05:07

标签: hibernate indexing lucene hibernate-search

在我的应用程序中,我必须将实体存储在Infinispan缓存中,并在这种类型的内存存储库中运行用户提供的搜索查询。问题是,我的实体有一系列字符串,让我们说它是这样的:

public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequestMessage req, TraceWriter log, ExecutionContext context)
{
    string path = context.FunctionDirectory;
    string newPath = Path.GetFullPath(Path.Combine(path, @"..\"));
    SqlServerTypes.Utilities.LoadNativeAssemblies(newPath);

我的问题是显然你不能像那样索引数组。显而易见的解决方案是创建Author对象并具有嵌入式索引,但这不是期望的选项(性能问题 - dto必须尽可能小)。

有没有其他方法可以索引这样的字段?

1 个答案:

答案 0 :(得分:1)

只需在数组属性上使用@IndexedEmbedded,Hibernate就会明白你的意思是索引数组元素而不是数组本身:

@Indexed(index = "bookIndex")
public class Book {
    @Field
    private Long id;
    @Field
    @IndexedEmbedded
    private String[] authors;
}

该功能未记录,因为它可能导致非原始数组元素的奇怪行为,但在您的情况下,您应该是好的。

或者,您可以编写自己的桥:https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#section-custom-bridges