lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Oezdemir, Senel" <Senel.Oezde...@drkw.com>
Subject RE: multiple fields to be indexed
Date Thu, 17 Jun 2004 12:00:59 GMT
Yes, use following code MultiFieldMultiQueryParser, it is not importet in
cvs Apache Lucene,
i will do this next, but you can use your own

multi Field wioth multi query



package  org.apache.lucene.queryParser;

import java.util.List;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.queryParser.CharStream;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.queryParser.QueryParserTokenManager;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.Query;


/**
 * A QueryParser which constructs queries to search multiple fields.
 *
 * @author <a href="mailto:senel.oezdemir@drkw.com">Senel Oezdemir</a>
 * @version $Revision: 1.3 $
 */
public class MultiFieldMultiQueryParser extends QueryParser 
{
    

    public MultiFieldMultiQueryParser(QueryParserTokenManager tm)
    {
        super(tm);
    }

    public MultiFieldMultiQueryParser(CharStream stream)
    {
        super(stream);
    }

    public MultiFieldMultiQueryParser(String f, Analyzer a)
    {
        super(f, a);
    }

	public static Query parse(List query, List fields, List flags,
Analyzer analyzer) throws Exception{
		BooleanQuery bQuery = new BooleanQuery();
		Query q = null;
		System.out.println("BEGIN QUERY");
		for (int i = 0; i <  fields.size(); i++)
		{
			//if( ( fields.get(i) != null ) || (query.get(i) !=
null) ){
			if( query.get(i) != null ){	
				try{
					
					System.out.println(fields.get(i) + "
: " + query.get(i));
					
					
					q = parse((String) query.get(i),
(String) fields.get(i), analyzer);
				}catch(Exception e ){e.printStackTrace();}
				
				int flag;
				if ( ((Boolean) flags.get(i)).booleanValue()
== true ){
					flag = 0;
				}else {
					flag = 1;
				}
				
				switch ( flag )
				{
					case 0:
						bQuery.add(q, true, false);
						break;
					case 1:
						bQuery.add(q, false, false);
						break;
					/** not supported
					case PROHIBITED_FIELD:
						bQuery.add(q, false, true);
						break;
					**/	
					default:
						bQuery.add(q, false, false);
						break;
				}
			}	
		}
			System.out.println("END QUERY");
	
System.out.println("--------------------------------------------------------
-----");
			return bQuery;
		
	  }
}

-----Original Message-----
From: jitender ahuja [mailto:ajitender@aalayance.com]
Sent: 17 June 2004 13:54
To: Lucene Developers List
Subject: Re: multiple fields to be indexed


Hi,
    Can u pl. clarify some more how to use the BooleanQuery class as I am
clueless still.
As far as I can gather it deals with multiple query terms and not with
searching a (may be single) given query term in multiple (indexed) fields.

Regards,
Jitender
----- Original Message ----- 
From: "Dmitry Serebrennikov" <dmitrys@earthlink.net>
To: "Lucene Developers List" <lucene-dev@jakarta.apache.org>
Sent: Monday, June 14, 2004 11:02 PM
Subject: Re: multiple fields to be indexed


> jitender ahuja wrote:
>
> >Hi all,
> >
> >I am trying to do a search on multiple fields of which some are indexed.
Now, a query can be posed to search in the indexed fields but the Hits class
object can have only one query object and the query class similarly can have
only one field on which the query is performed.
> >
> Take a look at BooleanQuery. That will allow you to combine multiple
> TermQueries, such that you can create a single query on different
> fields. That should do the trick.
>
> Good luck!
> Dmitry.
>
> >Now, to have multiple queries I need to obtain multiple Hits class
objects that are then merged  together in one array. But, I do not know how
to maintain the scorings obtained by different Hits class objects. If
somebody has tried such a thing or a different mechanism to feed a query to
different query objects, then pl. respond.
> >Actually I have not tried the above option of merging the results in a
final array but I feel that it should work.
> >
> >Regards
> >Jitender
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: lucene-dev-help@jakarta.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-dev-help@jakarta.apache.org


--------------------------------------------------------------------------------
The information contained herein is confidential and is intended solely for the
addressee. Access by any other party is unauthorised without the express
written permission of the sender. If you are not the intended recipient, please
contact the sender either via the company switchboard on +44 (0)20 7623 8000, or
via e-mail return. If you have received this e-mail in error or wish to read our
e-mail disclaimer statement and monitoring policy, please refer to 
http://www.drkw.com/disc/email/ or contact the sender. 3167
--------------------------------------------------------------------------------


---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-dev-help@jakarta.apache.org


Mime
View raw message