Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: FacetingRequest working for wrong reason?
PostPosted: Tue May 15, 2012 2:02 am 
Newbie

Joined: Tue Oct 09, 2007 10:48 pm
Posts: 11
Hi,

We have a parent-child relationship in our indexed domain objects, and all child and parent fields are in the same Lucene index.

Specifically, we have:

  • AbstractItem
  • PhysicalItem extends AbstractItem
  • DigitalItem extends AbstractItem
  • IntellectualItem extends AbstractItem

The concrete classes all have the identical annotation:
Code:
@Indexed(index = "Item")

We are including facets in our search, and a search needs to return all item types (i.e., instances of PhysicalItem, DigitalItem and IntellectualItem).

However, for constructing the QueryBuilder in order to construct a FacetingRequest, we can only specify a single entity. This can't be AbstractItem as it's abstract, so we are currently - arbitrarily - picking one of the subclasses.

So:
Code:
QueryBuilder builder = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(IntellectualItem.class).get();

For a search, this returns identical facet results regardless which subclass I use in forEntity() but the technique seems a bit odd and fragile. I suspect this is currently working fine because all of the subclasses are using the same Lucene index.

So, my questions are:

1. Is this approach indeed a bit suspect?
2. Is there a better approach? (I see that there is a TODO in QueryContextBuilder that there should be a forEntities() method written)

I guess if I wanted to be really safe I could construct separate faceting requests for each subclass, but this seems like a reasonable amount of bother...

Thanks,
Matt


Top
 Profile  
 
 Post subject: Re: FacetingRequest working for wrong reason?
PostPosted: Wed May 16, 2012 10:58 am 
Hibernate Team
Hibernate Team

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

Quote:
1. Is this approach indeed a bit suspect?


Yes. It works, but a QueryContextBuilder#forEntities and maybe a QueryContextBuilder#forIndex should be added to create a more intuitive API.
This should mirror a little how you for example can access IndexReaders. There is a IndexReaderAccessor#open(Class<?>... entities) and IndexReaderAccessor#open(String... indexNames).

Quote:
2. Is there a better approach? (I see that there is a TODO in QueryContextBuilder that there should be a forEntities() method written)


Not at the moment. It really needs someone to implement the TODOs. We are always looking for some helping hands :-)

--Hardy


Top
 Profile  
 
 Post subject: Re: FacetingRequest working for wrong reason?
PostPosted: Wed May 16, 2012 7:48 pm 
Newbie

Joined: Tue Oct 09, 2007 10:48 pm
Posts: 11
Lovely, thanks Hardy. Believe me - I'd be very happy to contribute to the Hibernate Search codebase if I had the time :(


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 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.