-->
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.  [ 5 posts ] 
Author Message
 Post subject: List must contain atleast one entry from another list
PostPosted: Mon Nov 28, 2011 6:58 pm 
Newbie

Joined: Mon Nov 28, 2011 6:46 pm
Posts: 3
I am using hibernate search, and I want to limit my search result, I assume I need to use filters, but I have not found any documentation describing how to produce a "or" query/filter

I have two classes.

class A {
List<B> bs;
}

I have indexed based on the ids of B.

I want to limit my result to only return those instances of A where the list of Bs is part of another list.

E.g.

A1 has B1, B2, B3 in the list

A2 has B3, B4 in the list

A3 has B5 in the list

I would like to be able to limit on Bs, e.g. I want all those As which has B2 or B5, which would limit my search to A1 and A3.
If i limit to those with B5, only A3 must be returned.

I am using both search and sort, so as far as I could read I cannot use "normal" criterias to achieve this.


Top
 Profile  
 
 Post subject: Re: List must contain atleast one entry from another list
PostPosted: Wed Nov 30, 2011 6:16 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
hi,

Have you tried using a TermQuery wrapped in a QueryWrapperFilter. You can build a normal query and then wrap it into the QueryWrapperFilter. Is this what you are after?

--Hardy


Top
 Profile  
 
 Post subject: Re: List must contain atleast one entry from another list
PostPosted: Fri Dec 02, 2011 6:18 am 
Newbie

Joined: Mon Nov 28, 2011 6:46 pm
Posts: 3
Well my problem is that I can't figure out how to create this term query

E.g.

new TermQuery(new Term(bs, <B2>))

This allows me to find all As which has B2 in the bs list, however, when I want to find those with EITHER B2 or B5, I dont seem to be able to do that.


Top
 Profile  
 
 Post subject: Re: List must contain atleast one entry from another list
PostPosted: Fri Dec 02, 2011 6:48 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

Use several TermQuerys and combine them in a BooleanQuery.


Top
 Profile  
 
 Post subject: Re: List must contain atleast one entry from another list
PostPosted: Fri Dec 02, 2011 9:06 am 
Newbie

Joined: Mon Nov 28, 2011 6:46 pm
Posts: 3
Thanks a lot,

I had tried to BooleanQuery, but used it together with other terms, which was why my Should clauses was not "required"

Thanks a lot for the tip


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