lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric Jain <>
Subject Re: search for and condition
Date Tue, 10 Aug 2004 13:01:23 GMT
> String line="text1 text2";
> Query q = MultiFieldQueryParser.parse(line,fields,analyzer);
> Hits hits =;
> Here search will take "text1 OR text2" Condition
> How  to make searh  "text1 and  text2" Condiation

I recently stumbled over the same issue - the setOperator method is not 
static and will therefore not effect the Query that is created by the 
parse method!

Until someone refactors the code (something along the lines of a 
QueryParserFactory might make sense), here is a workaround:

public Query parse(String query, String[] fields, Analyzer analyzer)
   BooleanQuery bQuery = new BooleanQuery();
   for (int i = 0; i < fields.length; i++)
     QueryParser parser = new QueryParser(fields[i], analyzer);
     Query q = parser.parse(query);
     bQuery.add(q, false, false);
   return bQuery;

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message