Search code examples
javahibernatelucenesearch-enginehibernate-search

Hibernate Search querying?


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?


Solution

  • 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