Hibernate 搜索查询?

发布于 2024-08-16 05:32:43 字数 695 浏览 6 评论 0原文

问候

我的域模型如下

class Species {
 private String name;
 ..
 ..
 List<Family> families;
}

class Family{
 private String name;
 private String locusId;
 ..
 List<Member> members; 
}

class Members{
 private String name;
 private String repTranscript;

}

我想使用“Hibernate Search”来执行查询,就像

org.hibernate.lucene.search.Query luceneQuery = parser.parse( "name:ASpeciesName or name:AGroupName or locudID:someLocusID" );
    org.hibernate.Query fullTextQuery = fullTextSession.createFullTextQuery( luceneQuery );
List result = fullTextQuery.list();

我想知道的那样,因为所有三个类都有相同的字段“name”,它是否会再次搜索所有类?

“结果”是否具有所有类型的对象?

Greetings

My domain model is as follows

class Species {
 private String name;
 ..
 ..
 List<Family> families;
}

class Family{
 private String name;
 private String locusId;
 ..
 List<Member> members; 
}

class Members{
 private String name;
 private String repTranscript;

}

I want to use 'Hibernate Search' to execute queries like

org.hibernate.lucene.search.Query luceneQuery = parser.parse( "name:ASpeciesName or name:AGroupName or locudID:someLocusID" );
    org.hibernate.Query fullTextQuery = fullTextSession.createFullTextQuery( luceneQuery );
List result = fullTextQuery.list();

I am wondering,since all three classes has same field 'name' does it search agains all the classes?

Does the 'result' has objects of all the types?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

三生池水覆流年 2024-08-23 05:32:43

它还取决于您如何建立索引。如果您单独为每个类建立索引(意味着每个类都有一个 @Indexed 注释),并且在创建 FullTextQuery 时没有指定预期的类类型,那么您在结果中确实会得到混合类。

但是,在您的示例中,您可以考虑在属性 familiesmembers 上使用 @IndexedEmbedded。在这种情况下,Lucene 文档中的字段名称将为 families.namefamilies.members.name

查看 Hibernate Search 在线文档和嵌入式索引功能。

——哈代

It also depends on how you index. If you index each class separately (meaning each class has a @Indexed annotation) and you don't specify a expected class type when creating the FullTextQuery you get indeed mixed classes in the result.

However, in your example you might consider using @IndexedEmbedded on the attribute families and members. In this case the field names in the Lucene Documents will families.name and families.members.name.

Have a look at the Hibernate Search online documentation and the embedded indexing feature.

--Hardy

入画浅相思 2024-08-23 05:32:43

从逻辑上讲,是的,因为查询中没有任何地方指定了所需的对象类型。

如果要将结果限制为特定类型,则需要将这些类型作为可变参数列表传递:

fullTextSession.createFullTextQuery( luceneQuery, A.class, B.class );

这是描述的在文档中

Logically, yes, because nowhere in the query have you specified the type of objects that you want.

If you want to restrict the results to specific types, you need to pass those types as a vararg list:

fullTextSession.createFullTextQuery( luceneQuery, A.class, B.class );

This is described in the docs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文