-->
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.  [ 4 posts ] 
Author Message
 Post subject: Searching collection of strings
PostPosted: Tue Feb 22, 2011 4:10 pm 
Newbie

Joined: Mon Nov 02, 2009 3:27 pm
Posts: 5
Hi,

I have a class Foo consisting of two fields (name and alternateNames) currently defined as follows:

@Entity
@Indexed
public class Foo {
@Field
String name ;

@ElementCollection
@IndexedEmbedded
Set<String> alternateNames = new HashSet<String>();
}
What I want is to search name and alternateNames together as part of one search operation, perhaps by adding the strings from alternateNames to name:? How can this be done? (The (excellent) Hibernate Search book doesn't seem to cover this case.)

Thanks for your help.


Top
 Profile  
 
 Post subject: Re: Searching collection of strings
PostPosted: Tue Feb 22, 2011 4:38 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
you can specify that they should both use the same field, but I'd really discourage this.
Once they are indexed this way, you're stuck and can't separate them if you need (for example, to apply some boosting).
Much better, have your queries written in such a way that they look into both fields.

As a sidenode, make sure you define a FieldBridge on alternateNames: @ElementCollection is not automatically supported right now.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Searching collection of strings
PostPosted: Thu Feb 24, 2011 5:37 pm 
Newbie

Joined: Mon Nov 02, 2009 3:27 pm
Posts: 5
Thanks
s.grinovero wrote:
you can specify that they should both use the same field, but I'd really discourage this.
Once they are indexed this way, you're stuck and can't separate them if you need (for example, to apply some boosting).
Much better, have your queries written in such a way that they look into both fields.

I see your point, but still don't know how to annotate the classes so I can search both fields. If it's just adding the FieldBridge mentioned below, could you please supply an example that would work? Thanks again.
s.grinovero wrote:
As a sidenode, make sure you define a FieldBridge on alternateNames: @ElementCollection is not automatically supported right now.


Top
 Profile  
 
 Post subject: Re: Searching collection of strings
PostPosted: Fri Feb 25, 2011 6:28 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
hi, sorry for the late answer. for some reason I missed the forum notification.

You need a custom FieldBridge on your alternateNames properties, which would look very similar to this one:
https://forum.hibernate.org/viewtopic.php?p=2441601#p2441601

Just make sure you cast the value to a Set and not to an Array as I did in that example.

To store both alternateNames and name, you just override the @Field attribute "name":
@Field(name="sameForBoth")

Still, I wouldn't do that, you should be better of making a Query targeting both fields.

_________________
Sanne
http://in.relation.to/


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