Lucene 索引和搜索不是工作子级到父级



类 A 是根实体,类 B 是关系为 1:n 的子实体。

我的示例代码:

@Entity
@Index
Class A {
@javax.persistence.Id
@DocumentId
@Column
private Long id;
@IndexedEmbedded
private List<B> elements;
}
@Entity
@Index
Class B {
@javax.persistence.Id
@DocumentId
@Column
private Long id;
@Column
private Long name;
@IndexedEmbedded
private A a;
}

我的 lucene 查询:

QueryBuilder builder = searchFactory.buildQueryBuilder().forEntity(B.class).get();
PhraseContext phraseCtx = builder.phrase().withSlop(2).boostedTo(25f);
PhraseMatchingContext phraseMatchingCtx = phraseCtx.onField("name");
Query query =  builder.all().createQuery();
FullTextQuery fullTextQuery = fullTextEntityManager.createFullTextQuery(query,B.class);
List<B> list = fullTextQuery.getResultList();

但它没有检索到结果。

你应该用@ContainedIn关系的B端的注释替换@IndexedEmbedded

假设 A 是 B 的父级,那么在 B 中您应该添加包含在注释中的:

@ContainedIn 
private A a;

不要忘记一对一/多对一映射

最新更新