Lucene hibernate搜索中的联接查询
我想写一个lucene查询,比如Lucene hibernate搜索中的联接查询,lucene,hibernate-search,Lucene,Hibernate Search,我想写一个lucene查询,比如 " from activity where metaentityByEntity.id in(select metaentityByEntity.id from userentity where user.id=1)" 我的域类是: public class Activity implements java.io.Serializable { private Long id; private Date timeStamp; priva
" from activity where metaentityByEntity.id in(select metaentityByEntity.id from userentity where user.id=1)"
我的域类是:
public class Activity implements java.io.Serializable {
private Long id;
private Date timeStamp;
private User user;
@IndexedEmbedded
private Metaentity metaentityByEntity;
}
public class Userentitydetail implements java.io.Serializable {
private Long id;
private Date timeStamp;
private Metaentity metaentityByEntity;
@IndexedEmbedded
private User user;
private Metaentity metaentityByProjectId;
private byte unfollow;
private Byte isAssociated;
}
但是如何编写lucene查询,从多个索引中进行搜索呢?基本上我在做hibernate搜索
谢谢。Lucene不是一个关系数据库,所以简单的回答是你不应该尝试连接;您的特定用例恰好是可实现的,因为您的查询可以大大简化 只需在链接后面的字段上创建查询:
QueryBuilder queryBuilder = fullTextSession.getSearchFactory()
.buildQueryBuilder()
.forEntity( Activity.class )
.get();
Query query = queryBuilder.keyword()
.onField( "metaentityByEntity.user.id" )
.ignoreAnalyzer()
.matching( 1 )
.createQuery();
您必须调整一些细节,因为您忽略了一些映射细节;例如,它可能需要
.matching( "1" )
相反。您的示例似乎不一致,搜索配置也不完整。如果您确实需要一个连接,并且它看起来与您在HQL中发布的内容类似,那么我建议您执行HQL查询,尤其是因为您没有使用任何全文搜索功能。@Hardy基本上我想编写一个lucene查询,它看起来像上面的hibernate查询。在hibernate搜索中,我可以使用@FieldBridge annotation来执行它。表示在活动表中使用“@FieldBridge on set”。