为了使用lucene进行搜索,我架了一座桥,
public class EntityIDFieldBridge implements FieldBridge {
@Override
public void set(String name, Object value, Document document, LuceneOptions luceneOptions) {
BaseEntity baseEntity = (BaseEntity) value;
if(value !=null){
Field field = new LongField(name, baseEntity.getId(),Field.Store.NO);
document.add(field);
}
}
}
当我寻找值(value)时,我没有得到正确的文件。当我搜索术语:*时,我确实得到了不为null的那些,因此我看到它被索引了……StringField正常工作。但是我认为这应该是一个漫长的 Realm 。有任何想法吗?
最佳答案
根据您提供的少量信息,我假设您不是要获取值null
。
Field Bridge提供了有关它是什么,lucene支持什么以及如何工作的更多信息:
In Lucene all index fields have to be represented as Strings. For this reason all entity properties annotated with @Field have to be indexed in a String form. For most of your properties, Hibernate Search does the translation job for you thanks to a built-in set of bridges. In some cases, though you need a more fine grain control over the translation process.
也适用于Null值
null elements are not indexed. Lucene does not support null elements and this does not make much sense either.
关于elasticsearch - 从自定义FieldBridge索引LongField问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62191290/