我是休眠搜索的新手,想知道我们如何在休眠搜索 6 中转换以下实现?在这种情况下哪种类型的桥更适合?
//ResourceAttributesBridge.java
公共类 ResourceAttributesBridge 实现 FieldBridge {
@Override
public void set(final String name, final Object value, final Document document, final LuceneOptions luceneOptions) {
.....
.....
luceneOptions.addFieldToDocument(fieldName, item, document);
....
}
}
//资源.java
公共类资源{
.......
.......
@MapKeyColumn(name = "attribute_name")
@Column(name = "attribute_value", nullable = false, length = 5000)
@Field(bridge = @FieldBridge(impl = ResourceAttributesBridge.class))
@Convert(attributeName = "value", converter = JSONObjectConverter.class)
@EqualsAndHashCode.Exclude
@ToString.Exclude
@OptimisticLock(excluded = true)
private Map<String, JSONObject> attributes;
......
.......
}
我尝试了这个解决方案,但它抛出异常 HSEARCH400504:
引起:org.hibernate.search.util.common.SearchException:HSEARCH400611:无效类型:'metadata.archetype'是一个值字段,而不是一个对象字段。
//资源.java
@MapKeyColumn(name = "attribute_name")
@Column(name = "attribute_value", nullable = false, length = 5000)
@PropertyBinding(binder = @PropertyBinderRef(type = ResourceAttributesBinder.class))
@Convert(attributeName = "value", converter = JSONObjectConverter.class)
@EqualsAndHashCode.Exclude
@ToString.Exclude
@OptimisticLock(excluded = true)
private Map<String, JSONObject> attributes;
//ResourceAttributesBinder.java
public class ResourceAttributesBinder implements PropertyBinder {
@Override
public void bind(PropertyBindingContext context) {
context.dependencies().useRootOnly();
IndexSchemaObjectField attributesMetadataField = context.indexSchemaElement().objectField("metadata");
attributesMetadataField.fieldTemplate(
"attributesMetadataValueTemplate_default",
f -> f.asString().analyzer( "english" )
);
context.bridge(Map.class,new ResourceAttributesPropertyBridge(attributesMetadataField.toReference()));
}
}
//ResourceAttributesPropertyBridge.class
公共类 ResourceAttributesPropertyBridge 实现 PropertyBridge {
@Override
public void write(DocumentElement target, Object bridgedElement, PropertyBridgeWriteContext context) {
final Map<String, Object> indexMap = (Map<String, Object>) bridgedElement;
.....
.....
target.addValue(fieldName,attributeValue.toString());
.....
}
}