-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate Search query for multiple table HQL
PostPosted: Wed Apr 15, 2009 10:25 am 
Newbie

Joined: Wed Apr 15, 2009 10:00 am
Posts: 1
I have to generate a query for two non related entities

query is 'select e0.a as a e1.b as b from entity0 as e0,entity1 as e1 where e0.id = e1.id '

I am using hibernate-search-3.1.0.GA:

I am not sure how to wrap the lucene query...

I tried

MultiFieldQueryParser mparser = new MultiFieldQueryParser(new String[] { "aTerm", "bTerm" },new StandardAnalyzer());

//aTerm,bTerm mapped to corresponding attributes in different classes


Query query = mparser.parse(query);
FullTextQuery fq = fs.createFullTextQuery(query, org.hibsearch.data.entity.Entity0.class,org.hibsearch.data.entity.Entity1.class);


When its exectued i get the results for each entities, as it generates two seperate SQLs than a single one (hib search works this way).

Any idea/hack to simulate the above query (joined version) in hibernate search ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 16, 2009 6:13 am 
Hibernate Team
Hibernate Team

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

It might help if you post your annotated entities. It is really hard to understand the problem from a single SQL statement.

Generally, HQL and Hibernate Search are not the same thing and serve different purposes. Hibernate Search offers fulltext search capabilities, something databases are normally quite bad in. It does not offer a replacement for SQL. In some use cases it might be required to mix both approaches. You might want to do a fulltext search to determine the entity ids of the entities matching the fulltext query. Then you would use the ids in some sort of HQL query to further limit your results.

Regarding your query. Using MultiFieldQueryParser basically combines the search terms with an 'OR'. This means all entities which either match 'aTerm' or 'bTerm' will be returned. I think you would have to build a much more complicated query using for example Lucene's BooleanQuery to get closer to what you are after.

--Hardy


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