我似乎无法使基本的FieldBridge
实施工作。看起来索引过程完全忽略@FieldBridge
注释。
以下是实施:
public class LocalisedInformationBridge implements FieldBridge {
@Override
public void set(String name, Object value, Document document, LuceneOptions luceneOptions) {
luceneOptions.addFieldToDocument(name + ".test", "test", document);
}
}
具有@FieldBridge
注释的实体:
@OneToMany(mappedBy = "product")
@MapKey(name = "languageCode")
@IndexedEmbedded
@FieldBridge(impl = LocalisedInformationBridge.class)
private Map<String, LocalisedProductInformation> localisedProductInformation;
包含的实体:
@ManyToOne
@JoinColumn(name="productId")
@ContainedIn
private Product product;
当我尝试搜索localisedProductInformation.test
字段时,我发现异常:
org.hibernate.search.exception.SearchException:无法找到字段 localisedProductInformation.test
以下是我如何索引数据:
FullTextEntityManager fullTextEntityManager =
Search.getFullTextEntityManager(entityManager);
fullTextEntityManager.createIndexer().startAndWait();
奇怪的是当我在set
类的LocalisedInformationBridge
方法上设置断点时,调试器不会停止程序的执行。我在这里缺少一些非常明显的东西吗?
答案 0 :(得分:0)
要知道的是,当您在容器属性(数组,集合或映射)上使用@IndexedEmbedded时,@ Field注释中定义的任何字段桥将应用于此属性值的元素。 因此,在您的情况下,字段桥将应用于地图的值,而不是地图本身。如果地图为空,则根本不会应用字段桥。这是你的情况吗?
这种行为无疑是有点奇怪(假设f = [int(x) for y in f for x in y]
的目的略有不同),但它已经被引入了一段时间并且修复它会导致依赖它的用户产生回归。因此,在发布新的主要版本之前,这可能会保持这种状态......