我有两个班:
A类:(待检索)
@Entity
@Indexed
Class A {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(updatable = false, nullable = false)
protected Long id;
@JsonIgnore
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "b_id", referencedColumnName = "id")
protected B b; // foreign key
}
字符串
B类:
@Entity
Class B {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(updatable = false)
@JsonIgnore
private Long id;
private String fieldToBeIndexed; // ** I want to index this field **
}
型
因为我正在做一个项目,搜索只针对A类:
例如:FullTextQuery fullTextQuery = fullTextEntityManager.createFullTextQuery(query,A);
我想通过在搜索框中传递B的字段(fieldToBeIndexed)的值来搜索A。我如何才能做到这一点。我如何索引B的字段(fieldToBeIndexed),以便可以根据B的字段(fieldToBeIndexed)搜索A。
1条答案
按热度按时间bqujaahr1#
您可以使用
@IndexEmbedded
来执行此操作:字符串
我假设您使用的是Hibernate Search 5,因此这里有指向该版本IndexedEmbedded文档的链接https://docs.jboss.org/hibernate/search/5.11/reference/en-US/html_single/#search-mapping-associated