-->
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: combining two(or more) query objects (AND)
PostPosted: Wed Jan 06, 2010 8:58 am 
Regular
Regular

Joined: Thu Nov 26, 2009 8:45 am
Posts: 78
Hi,
i want my user to enter a (or several) searchword(s) and also a daterange. i'm building two querys like this:
Code:
         for(int i = 0; i < words.length; i++){
            if(words[i] instanceof String){
               query = MultiFieldQueryParser.parse((String)words[i], fields, boolArr,new GermanAnalyzer());
               queryList.add(query);


now i have all my querys in an array (queryList.toArray() returns Object[]). What i'm tryin to reach is now to merge all these queries in the array into one query like:

(query1) AND (query2) AND ... AND (queryN)

i already found the static method :
Code:
Query.mergeBooleanQueries(queryArray);

but this ORs all the querys which is not my intention. Also i already build the wanted query by myself within a string, but i just found
Code:
Fulltextsession.createQuery(String string)

but that returns a hibernate query.
Is there a way i can use this (or any other approach) to achieve my goal?


Top
 Profile  
 
 Post subject: Re: combining two(or more) query objects (AND)
PostPosted: Wed Jan 06, 2010 9:11 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Use Lucene's BooleanQuery and add you query elements using the add method specifying the BooleanClause.Occur.MUST parameter for each element.


Top
 Profile  
 
 Post subject: Re: combining two(or more) query objects (AND)
PostPosted: Wed Jan 06, 2010 9:37 am 
Regular
Regular

Joined: Thu Nov 26, 2009 8:45 am
Posts: 78
exactly what i was looking for. thx a lot!


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.