-->
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: [Hibernate Search] Searching by properties of nested object
PostPosted: Fri Jun 08, 2012 12:56 pm 
Newbie

Joined: Fri Jan 18, 2008 2:32 pm
Posts: 8
Hi,

I am trying to find out how to search by properties of a specific nested object. My model looks something like this: X is a top level entity that contains a collection of Y, and Y has two properties: id and name. I want to find all X instances that contain a Y with specific id and name. Searching by X.Y.id and X.Y.name is not enough because it won't guarantee that id and name matched properties on the same Y instance.
Is it possible to do this?

Thanks,

_________________
Gabriel Axel
http://www.gabiaxel.com/


Top
 Profile  
 
 Post subject: Re: [Hibernate Search] Searching by properties of nested object
PostPosted: Fri Jun 08, 2012 6:10 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Quote:
I want to find all X instances that contain a Y with specific id and name. Searching by X.Y.id and X.Y.name is not enough because it won't guarantee that id and name matched properties on the same Y instance.

You are correct, you won't have that guarantee.

Quote:
Is it possible to do this?

Not really. You have to bear in mind that Lucene is not relational at all: we can de-normalize some kind of relations (mostly ManyToOne and OneToOne), but your case is the typical example of what is not supported by the engine without some tricks from your part.

One option would be to encode id+name in the same field. This is easy if "name" is just a keyword for which you don't want to apply an analyzer (you can't let an Analyzer blindly process your tricked value or it will split it and it won't work). If you need to analyze the name, you'll have to pre-tokenize it and then store in the field as id+token1, id+token2, ..., id+tokenN. Remember: you can index the same field multiple times.

To query such an encoded field, would need some similar token manipulation: not trivial but doable.

The good news is that Lucene is coming with a new (limited) JOIN functionality; what you need to do might become simpler in the future but the upcoming feature is going to have a significant performance hit: if you can apply the above trick that should be best.

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


Top
 Profile  
 
 Post subject: Re: [Hibernate Search] Searching by properties of nested object
PostPosted: Sat Jun 09, 2012 2:16 pm 
Newbie

Joined: Fri Jan 18, 2008 2:32 pm
Posts: 8
Thanks for the answer. I came up with a solution that suites my needs: I wrote a FieldBridge for the collection, which iterates over the elements and uses each element ID (which is a Hibernate-generated UUID, so it's safe to use it) as part of the Lucene field name. Then I can use this field name in my queries with ignoreFieldBridge().

_________________
Gabriel Axel
http://www.gabiaxel.com/


Top
 Profile  
 
 Post subject: Re: [Hibernate Search] Searching by properties of nested object
PostPosted: Sat Jun 09, 2012 3:28 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
right, that looks like a good solution

_________________
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.