gpt4 book ai didi

java - Hibernate 搜索在索引中存储 byte[]

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

我的 POJO 中有以下配置:

@Field(index = Index.NO, store = Store.YES)
private byte[] file;

当我启动我的 Apps 容器时,出现以下异常:

Caused by: org.hibernate.search.SearchException: Unable to guess FieldBridge for file at org.hibernate.search.bridge.BridgeFactory.guessType(BridgeFactory.java:249) at org.hibernate.search.engine.AbstractDocumentBuilder.bindFieldAnnotation(AbstractDocumentBuilder.java:707) at org.hibernate.search.engine.AbstractDocumentBuilder.checkForField(AbstractDocumentBuilder.java:568) at org.hibernate.search.engine.AbstractDocumentBuilder.initializeMemberLevelAnnotations(AbstractDocumentBuilder.java:436) at org.hibernate.search.engine.AbstractDocumentBuilder.initializeClass(AbstractDocumentBuilder.java:383) at org.hibernate.search.engine.AbstractDocumentBuilder.checkForIndexedEmbedded(AbstractDocumentBuilder.java:631) at org.hibernate.search.engine.AbstractDocumentBuilder.initializeMemberLevelAnnotations(AbstractDocumentBuilder.java:440) at org.hibernate.search.engine.AbstractDocumentBuilder.initializeClass(AbstractDocumentBuilder.java:383) at org.hibernate.search.engine.AbstractDocumentBuilder.(AbstractDocumentBuilder.java:134) at org.hibernate.search.engine.DocumentBuilderIndexedEntity.(DocumentBuilderIndexedEntity.java:178) at org.hibernate.search.spi.SearchFactoryBuilder.initDocumentBuilders(SearchFactoryBuilder.java:375) at org.hibernate.search.spi.SearchFactoryBuilder.buildNewSearchFactory(SearchFactoryBuilder.java:262) at org.hibernate.search.spi.SearchFactoryBuilder.buildSearchFactory(SearchFactoryBuilder.java:144) at org.hibernate.search.event.FullTextIndexEventListener.initialize(FullTextIndexEventListener.java:151) at org.hibernate.event.EventListeners$1.processListener(EventListeners.java:198) at org.hibernate.event.EventListeners.processListeners(EventListeners.java:181) at org.hibernate.event.EventListeners.initializeListeners(EventListeners.java:194) ... 41 more

如何在 Hibernate Search (Lucene) 索引中存储字节数组?

最佳答案

您需要一个 field bridge .

例如:

@Field(index = Index.NO, store = Store.YES)
@FieldBridge(impl = MyFieldBridge.class)
private byte[] file;


//The file bridge
public class MyFieldBridge implements StringBridge {

@Override
public String objectToString(final Object object) {

byte[] file = (byte[]) object;

return MagicFileUtil.getTextContent(file)
}
}

关于java - Hibernate 搜索在索引中存储 byte[],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7796616/

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