views:

106

answers:

2

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?

+2  A: 

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.

skaffman
+2  A: 

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 *Document*s will families.name and families.members.name.

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

--Hardy

Hardy