-->
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: How do I use JOINS in my Hibernate Search (FullText) query??
PostPosted: Sun May 04, 2008 1:05 pm 
Beginner
Beginner

Joined: Mon Aug 13, 2007 2:37 am
Posts: 22
Hi guys,

I'm new to using Hibernate Search and I have no clue what I'm doing. I have an existing hibernate search query that I'm trying to change to that advantage of FullText query capabilities. My current query uses JOINs and I'm wondering how I can write JOIN queries with fullTextSession.createFullTextQuery().

Here's my current code:
Code:

                    queryStringBuff.append(" FROM Busines as B  ");
                    queryStringBuff.append(" where B.Business_Id IN ( ");
                    queryStringBuff.append("       Select B.Business_Id from Busines as B ");
                    queryStringBuff.append("       JOIN Business_Address as BA ON B.Business_Id = BA.Business_Id");
                    queryStringBuff.append("       JOIN Address as A ON A.Address_Id = BA.Address_Id ");
                    queryStringBuff.append("       WHERE ");
                    queryStringBuff.append(" A.City_Name  like '%" + criteria_.cityName + "%' ");
                    queryStringBuff.append("       and A.state = '" + criteria_.stateName + "')"
               queryStringBuff.append(" AND ");
                    queryStringBuff.append(" ( ");
                    queryStringBuff.append("    B.Business_Name like '%" + criteria_.businessName + "%')" );



In this example, the 3 tables I need to join are BUSINESS, BUSINESS_ADDRESS, and ADRESS

And I have selected BUSINESS.Business_Name, ADDRESS.City_Name, ADDRESS.State and the 3 IDs as the indexed fields.

How can I change this to a FullTextQuery?
This is what I have so far:
Code:

                  FullTextSession fullTextSession = Search.createFullTextSession( this.getSession() );
                  MultiFieldQueryParser parser = new MultiFieldQueryParser(new String[]{"businessName"}, new StandardAnalyzer());

                  org.apache.lucene.search.Query query = parser.parse(searchString);

                  searchQry = fullTextSession.createFullTextQuery(query, Business.class);
               
               countQry = searchQry;
               
               result = paginator.getPaginatdResult(session,countQry,searchQry,paginationControl_);



Unfortunately, they are NO examples on using JOINS out there!!! Please...Help!


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 05, 2008 6:31 am 
Hibernate Team
Hibernate Team

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

there are no JOIN examples for Hibernate Search, because there is no JOIN. The concepts of a freetext search engine (Lucene) and a ORM mapper (Hibernate) are very different. A Lucene index does not contain any relational information. Index documents are basically sets of key value pairs.


Regarding your problem I recommend you have a look at the Hibernate Search documentation and how to index embedded objects. http://www.hibernate.org/hib_docs/search/reference/en/html_single/#d0e1322. You probably want to index the address fields as part of the Business index. Once you got the index right you can use a MultiFieldQueryParser or use other classes from Lucene's broad query API to construct your query.

Hope this helps.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 05, 2008 4:50 pm 
Beginner
Beginner

Joined: Mon Aug 13, 2007 2:37 am
Posts: 22
I came across this approach for the Join. Is this a corrrect solution?

Code:
                  FullTextSession fullTextSession = Search.createFullTextSession( session );
                  MultiFieldQueryParser parser = new MultiFieldQueryParser(new String[]{
                  "businessName", "businessAddresses.address.cityName", "businessAddresses.address.state"}, new StandardAnalyzer());
                  org.apache.lucene.search.Query query = parser.parse(searchString);
                  searchQry = fullTextSession.createFullTextQuery(query, BusinessCbo.class);
               countQry = searchQry;
               result = paginator.getPaginatdResult(session,countQry,searchQry,paginationControl_);



Refer to:
http://forum.hibernate.org/viewtopic.php?t=986506


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 06, 2008 5:43 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Yes, that's what I meant with indexed embedded. If your Business entity has a collection of Adresses named businessAddresses the document field names would however per default be businessAddresses.cityName and businessAddresses.state.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 06, 2008 2:51 pm 
Beginner
Beginner

Joined: Mon Aug 13, 2007 2:37 am
Posts: 22
Thanks Hardy for your response. That make actually makes sence.

My next struggle is how I need to specify the embedded/joins using Hiberate annotation across the 3 tables.

I've posted the question on:
http://forum.hibernate.org/viewtopic.php?t=986506

Looking at my configuration, if you can answer my question in that posting that would help me a lot to make progress. I haven't used annotations before so I'm stuck.


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.