-->
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.  [ 9 posts ] 
Author Message
 Post subject: @IndexedEmbedded
PostPosted: Tue Jul 21, 2009 9:32 am 
Newbie

Joined: Thu Jul 16, 2009 2:15 am
Posts: 5
Hi all,

I have a small problem. I have a sample application with two classes with a set of fields which I have annoted with HS and is being index and searched properly. But I have a problem with a field which is mapped to another class as given below.

@ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY)
@JoinColumn(name = "proc_code_oid")
@IndexedEmbedded
public PlatterCode getPlatterCode() {
return platterCode;
}

I'm not able to index/search this field even after the field being annoted as @IndexedEmbedded. I am aiming to search for the 'platterCode' of the other table through this table.

Any suggestion would of tremendous help.

Thanks in advance.


Top
 Profile  
 
 Post subject: Re: @IndexedEmbedded
PostPosted: Tue Jul 21, 2009 9:34 pm 
Newbie

Joined: Wed Jul 15, 2009 12:34 pm
Posts: 18
How are you searching for this field? Don't forget that, by default, your search field in this case is prefixed by "platterCode". So if you have a field named as "code" in the PlatterCode class, you have to refer it as "platterCode.code", in order to be able to search over it. If you want to be sure that the PlatterCode is really being embedded in the document, use Luke to check your indices.


Top
 Profile  
 
 Post subject: Re: @IndexedEmbedded
PostPosted: Wed Jul 22, 2009 3:06 am 
Newbie

Joined: Thu Jul 16, 2009 2:15 am
Posts: 5
Thanks a lot for your reply. I checked the indices with luke and found that the "platterCode" is not being embedded in it. I guess I have not annoted the field properly?


Top
 Profile  
 
 Post subject: Re: @IndexedEmbedded
PostPosted: Wed Jul 22, 2009 6:53 pm 
Newbie

Joined: Wed Jul 15, 2009 12:34 pm
Posts: 18
Well, if it's not there in the indices, then something is wrong with your annotations. Did you put the @Field annotation in the PlatterCode class?


Top
 Profile  
 
 Post subject: Re: @IndexedEmbedded
PostPosted: Thu Jul 23, 2009 2:05 am 
Newbie

Joined: Thu Jul 16, 2009 2:15 am
Posts: 5
Yes I have added the @Field annotation in the PlatterCode class.


Top
 Profile  
 
 Post subject: Re: @IndexedEmbedded
PostPosted: Thu Jul 23, 2009 10:33 am 
Newbie

Joined: Wed Jul 15, 2009 12:34 pm
Posts: 18
Could you show a sample of the code with the annotations and how you are trying to search?


Top
 Profile  
 
 Post subject: Re: @IndexedEmbedded
PostPosted: Fri Jul 24, 2009 7:32 am 
Newbie

Joined: Thu Jul 16, 2009 2:15 am
Posts: 5
This is the annotation in the TreatmentPlatter.java class.


@ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.lazy)
@JoinColumn(name = "proc_code_oid")
@IndexedEmbedded
public PlatterCode getPlatterCode() {
return platterCode;
}

this is annotation in the PlatterCode.java class( I am indexing this class also)

@Column(name = "oid" , nullable = false )
// For a more generic generator, chose AUTO.
@Id @GeneratedValue(strategy=javax.persistence.GenerationType.AUTO)
@DocumentId
@Field(index = Index.UN_TOKENIZED, store = Store.YES)
public Long getOid() {
return oid;
}


-------------------------------------------------------------------------------------------------------------------------------
And this is how I am searching


String[] fields = new String[]{"oid","platterCode","code","description","location","dxLocation"};
MultiFieldQueryParser parser = new MultiFieldQueryParser(fields, new StandardAnalyzer());
String searchString = "platter code 3";
org.apache.lucene.search.Query query = parser.parse(searchString);

// wrap Lucene query in a org.hibernate.Query
org.hibernate.Query hibQuery = fullTextSession.createFullTextQuery(query, TreatmentPlatter.class, PlatterCode.class);

List result = hibQuery.list();

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
The platter codes are stored in the plattercode table. The treatmentPlatter table stores only the 'oid' of the particular plattercodes.

Iam able to search both the tables very well for the native string fields, but not for the' @joincolumn' fields. I tried using the 'depth' parameter for the '@IndexedEmbedded' annotation but encountered an exception.


My requirement: I am indexing both the PlatterCode.java and TreatmentPlatter.java classes. I need all the instances of a particular 'platter code' from both the tables.

Thanks a lot for your time, really appreciate it.


Top
 Profile  
 
 Post subject: Re: @IndexedEmbedded
PostPosted: Fri Jul 24, 2009 2:34 pm 
Newbie

Joined: Wed Jul 15, 2009 12:34 pm
Posts: 18
Hmm.. I'm not sure if I understood what you're trying to do but let's try this: If you're embedding the PlatterCode class in the TreatmentPlatter class, I suppose you want to query TreatmentPlatter instances that have a certain platter code, right? In this scenario, you probably have an attribute that maps the platter code in your PlatterCode class, let's call it platterCode. Now, you have to annotate this platterCode attribute with @Field, not the oid attribute. So you can search like this:

Code:
String[] fields = new String[]{"oid","platterCode","code","description","location","dxLocation", "platterCode.platterCode"};
MultiFieldQueryParser parser = new MultiFieldQueryParser(fields, new StandardAnalyzer());
String searchString = "platterCode.platterCode: 3"; // here you want to find platter codes with code '3'
org.apache.lucene.search.Query query = parser.parse(searchString);

// wrap Lucene query in a org.hibernate.Query
org.hibernate.Query hibQuery = fullTextSession.createFullTextQuery(query, TreatmentPlatter.class);
List result = hibQuery.list();


Is this what you wanted to do?


Top
 Profile  
 
 Post subject: Re: @IndexedEmbedded
PostPosted: Mon Jul 27, 2009 6:30 am 
Newbie

Joined: Thu Jul 16, 2009 2:15 am
Posts: 5
Yes thats is what I intend to do. I have also annotated the 'platterCode' field like you had mentioned since I am indexing that class also, I tried searching the way you had suggested, but still the problem persists. I guess the mapping provided is incorrect. I will look into it and get back to you.

Thanks a lot for your help. Will let you know.
Aditya


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 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.