`

Unable to guess FieldBridge for 字段名

 
阅读更多
http://stackoverflow.com/questions/7796616/hibernate-search-storing-byte-in-index

找到这个字段的定义, 或者getter方法.

You will need a field bridge.

For example:
@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)
    }
}


由于没有找到这个MagicFileUtil类,所以自己转换byte[]==>String
http://bbs.csdn.net/topics/297981
MyFieldBridge.java改成
import org.hibernate.search.bridge.StringBridge;
/**
 * Created with IntelliJ IDEA.
 * User: pandy
 * Date: 13-7-3
 * Time: 下午2:02
 * To change this template use File | Settings | File Templates.
 */
public class MyFieldBridge implements StringBridge {

    @Override
    public String objectToString(final Object object) {

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

        //return MagicFileUtil.getTextContent(file);
        return String.valueOf(file);
    }
}


如果可以, 最好到org.hibernate.search.bridge.builtin去寻找相应的Bridge类.  如果不行, 看就情况对字段的特殊类型做实现, 比如实现TwoWayStringBridge.
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics