-->
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: Fulltext search across more entities
PostPosted: Wed Jan 12, 2011 7:30 pm 
Newbie

Joined: Fri Mar 06, 2009 10:06 am
Posts: 2
Hello.
I'm pretty new to Hibernate Search and now I'm trying to figure out the first bigger problem.

I'm able to make fulltext search on one entity using QueryBuilder. But I would like to make similar query across more entities that are not in relation - with one query and using standard Hibernate Search API. Is that even possible?

Thanks...


Top
 Profile  
 
 Post subject: Re: Fulltext search across more entities
PostPosted: Thu Jan 13, 2011 5:29 am 
Hibernate Team
Hibernate Team

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

Having a QueryBuilder for multiple entities is at the moment not possible. It is an outstanding feature.
It is important to understand though that this does not mean that you cannot take the Lucene query generate by the query builder and apply a completely different set of filter classes. Let me explain. The most common usecase would be:
Code:
QueryBuilder qb = fullTextSession.getSearchFactory().buildQueryBuilder().
    forEntity( Foo.class ).get();

Query query = qb.keyword()
                     .onField( "bar" )
             .matching("fubar")
            .createQuery();

FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery(query, Foo.class);
fullTextQuery.list();

You are creating a query using the query builder for a certain entity and then apply the same entity as filter to the createFullTextQuery call. However, the Lucene query generated by the query builder does have no "enforced" connection to the entity passed to forEntity. The passed entity is in this case not a query restriction, but it just provides context for the query builder to apply automatic field conversion (you can eg pass an actual Date instance into matching which automatically gets transformed to a query string).
The entities passed to createFullTextQuery, however, apply filtering on the specified types. This also means that if you build a query for entity Foo and you have a second entity Bar which also has a field bar you could do something like this:
Code:
FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery(query, Bar.class);

I hope that was not too confusing. Arguably the query builder API implies different behavior. I guess the documentation could be cleared or maybe the query builder should actually add an entity restriction.

--Hardy


Top
 Profile  
 
 Post subject: Re: Fulltext search across more entities
PostPosted: Thu Jan 13, 2011 6:13 am 
Newbie

Joined: Fri Mar 06, 2009 10:06 am
Posts: 2
Thanks, that was really helpful. I have altered my project acordingly and it seems to work like a charm :-)


Top
 Profile  
 
 Post subject: Re: Fulltext search across more entities
PostPosted: Fri Nov 09, 2012 11:50 am 
Newbie

Joined: Tue Jul 19, 2011 2:16 pm
Posts: 19
Hi,

A few year later, I have the same problem... but no solution.

At the beginning, I would like to give the main abstract class for the entities requested, like the following :
Code:
QueryBuilder qb = fullTextSession.getSearchFactory().buildQueryBuilder().
    forEntity( AbstractFoo.class ).get();

Query query = qb.keyword()
                     .onField( "bar" )
             .matching("fubar")
            .createQuery();

FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery(query, AbstractFoo.class);
fullTextQuery.list();


But it seems it doesn't work...

What is your solution ?


Top
 Profile  
 
 Post subject: Re: Fulltext search across more entities
PostPosted: Sat Nov 10, 2012 6:30 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi andilo, what do you mean with "it doesn't work" ? Could you provide some more details of what you expect and what you're actually having?

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