-->
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.  [ 3 posts ] 
Author Message
 Post subject: search with filtering on collection
PostPosted: Wed Jul 06, 2011 2:52 pm 
Newbie

Joined: Thu Jul 19, 2007 11:21 am
Posts: 12
Hi there,

I have the following mapping in hibernate/hibernate search:

entity B{
some other properties that go in filtering below (such as title)
property enum status [ACTIVE|INACTIVE]
}

entity A{
Set<entity B> Bs
}

my search results are always A, and i'd like to search for A items containing ACTIVE B entities with a specific title

ex A.B = { (title1, ACTIVE), (title2, ACTIVE), (title3, INACTIVE)}
in this case a search for title3 shouldn't bring any A results as the status filtering is always applied

however, the way i wrote my query (a boolean query where i append this: query.add(qb.keyword().onField("A.B.status").matching(ACTIVE).createQuery(), MUST);

the example above will actually bring the title3 result just because the index contains 2 other occurences of A.B.Status equal to ACTIVE.

many thanks for any idea on how to fix this!

-val


Top
 Profile  
 
 Post subject: Re: search with filtering on collection
PostPosted: Thu Jul 07, 2011 8:40 am 
Hibernate Team
Hibernate Team

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

this is maybe a misconception on your part. Hibernate Search won't filter collection items away. You are doing a search for instances of class A. Obviously the instance with two active B instances and one inactive one is a match to your query. In this case entity A is returned fully populated (give or take lazy loading). Search is not removing collection elements!

You can of course let your search return instances of B, meaning you search the B index. Whether this is of any use for you depends on the usecase. In Hibernate Core you can specify a 'where' condition for collection loading. In this case you could restrict the loading in a way that only B instances with an active status will be loaded. But this of course something completely different.

--Hardy


Top
 Profile  
 
 Post subject: Re: search with filtering on collection
PostPosted: Thu Jul 07, 2011 9:14 am 
Newbie

Joined: Thu Jul 19, 2007 11:21 am
Posts: 12
thanks for your answer!

i see my post wasn't clear enough or i don't completely get the answer. I didn't mean the search would remove collection items. on the contrary, the collections are flattened (see para 4.2.1from hibernate search in action), ie all items in a collections associated with container A get into the same lucene field.

I could build the query the other way (from B to A) -- only to filter on this condtion, or -- i have heard -- using filters? I'd like some feedback on this latter as the first approach might involve too much work ( i have multiple advanced search queries that do query on many fields (almost all fields in entity and associations even) --this is the requirement really, they say that it might be useful for reporting purposes)

So, could anyone provide me with an example of a working filter?

For now i can think of a filter that would be something like a list of (+id:id1 +status:active) where the first param would be injected, only problem is i'd need an extra query to find all the ids of B belonging to A. i hope there is a better solution than this.

many thanks,
-val


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