-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Embedded class (component). How to search?
PostPosted: Tue Nov 18, 2008 5:59 am 
Beginner
Beginner

Joined: Thu Jun 07, 2007 2:38 am
Posts: 28
Location: Italy, Rome
Class EmailAddress embeds via the Hibernate mapping file the class ShortName
Code:
@Indexed
public class EmailAddress {

   @DocumentId
   private long id;

   private ShortName address;



Code:
public class ShortName {
   
   @Field(index = Index.TOKENIZED, store = Store.NO)   
   private String value;


Code:
      
FullTextSession fullTextSession = Search.createFullTextSession(this.getSession());
MultiFieldQueryParser parser = new MultiFieldQueryParser(new String[] { "address", "address.value" }, new StandardAnalyzer());
org.apache.lucene.search.Query query = null;
try {
   query = parser.parse(searchTerm);
} catch (ParseException e) {
   e.printStackTrace();
}
org.hibernate.Query hibQuery = fullTextSession.createFullTextQuery(query, EmailAddress.class);
List<EmailAddress> result = hibQuery.list();


Unfortunately the search does not result anything! How do I tell Hibernate search that I am using a component (embedded class). What is the notation for the fields for the MultiFieldQueryParser?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 18, 2008 6:25 am 
Beginner
Beginner

Joined: Thu Jun 07, 2007 2:38 am
Posts: 28
Location: Italy, Rome
Mmm, I found the answer, ahum....

Code:
@Indexed
public class EmailAddress {

   @DocumentId
   private long id;

   @IndexedEmbedded
   private ShortName address;

   @IndexedEmbedded
   private String32 type;


Code:
@Indexed
public class ShortName {

   
   @Field(index = Index.TOKENIZED, store = Store.NO)   
   private String value;


Code:
FullTextSession fullTextSession = Search.createFullTextSession(this.getSession());
MultiFieldQueryParser parser = new MultiFieldQueryParser(new String[] { "address.value" , "type.value" },
new StandardAnalyzer());
org.apache.lucene.search.Query query = null;
try {
   query = parser.parse(searchTerm);
} catch (ParseException e) {
   e.printStackTrace();
   throw new GeoNetworkException(e);
}
org.hibernate.Query hibQuery = fullTextSession.createFullTextQuery(query, EmailAddress.class);
List<EmailAddress> result = hibQuery.list();
return result;


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.