-->
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: Does Hibernate Search support 'AND' and 'OR' queries?
PostPosted: Sun Jun 08, 2008 7:06 am 
Beginner
Beginner

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

I'm trying to write a search engine query for a website. So, I'm wondering if Hibernate Search supports 'AND' and 'OR' fullText queries? Please, I would apprecite any examples you can provide.

Here's my query:

Code:

                  FullTextSession fullTextSession = Search.createFullTextSession( session );
                  QueryParser parser = new QueryParser("businessId", new StandardAnalyzer());
                  
                  org.apache.lucene.search.Query query = parser.parse("businessName:" + keywords + "~");
                  query = parser.parse("businessAddresses.address.cityName:" + criteria_.cityName + "~");
                  query = parser.parse("businessAddresses.address.state:" + criteria_.stateName);
                  query = parser.parse("businessServiceCategories.serviceCategory.serviceCategoryName:" + keywords + "~");
                  query = parser.parse("businessServices.service.serviceName:" + keywords + "~");
                   query = parser.parse("businessSubCategories.serviceSubCategory.serviceSubCategoryName:" + keywords + "~");

                  Criteria criteria = fullTextSession.createCriteria( BusinessCbo.class )
                  .setFetchMode( "businessAddresses", FetchMode.JOIN )
                  .setFetchMode( "businessServiceCategories", FetchMode.JOIN )
                  .setFetchMode( "businessServices", FetchMode.JOIN )
                  .setFetchMode( "businessSubCategories", FetchMode.JOIN );
                  searchQry = fullTextSession.createFullTextQuery( query ).setCriteriaQuery( criteria );
                                    
               result = paginator.getPaginatdResult(session,countQry,searchQry,paginationControl_);



I need to find out if a "keyword" matches a service a business offers OR a category the business fulls in OR a sub category the business fulls in for a given city AND state.

It looks my query above it just doing AND on all the possible search criterias, which I don't want.

Please...HeLP.


Top
 Profile  
 
 Post subject: We can use And ,Or while searching
PostPosted: Sun Jun 08, 2008 3:21 pm 
Newbie

Joined: Sat Jun 07, 2008 5:44 am
Posts: 2
Hi ,

If ur bean class has variables declared as businessid and businessname and the respective setters and getters.


Business name is a string
If u have a lot of business names and you want to find names that have JOHN in them or LILY in them

org.apache.lucene.search.Query query = parser.parse(" businessname:JOHN Or businessname:LILY);


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 09, 2008 7:10 am 
Hibernate Team
Hibernate Team

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

Yes, Hibernate Search supports logical operators like AND and OR. Or I should better say, when it comes to querying you have the full functionality of Lucene available and in fact you should check against the Lucene API on what you can do and what not. See http://lucene.apache.org/java/docs/queryparsersyntax.html for Lucene's query parser syntax.

Also check the Lucene API regarding the different options to programmatically construct a query. If you have many different criteria (coming eg from different input fields on the web site) it might be easier to generate a query for each of them and then combine them using a BooleanQuery.

In your particular code example I would expect that only the last query string gets used for the search. The rest is lost.

Search also the forum, I believe there were similar questions before.

Good luck,
hardy


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.