lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Itamar Syn-Hershko <>
Subject Make MultiFieldQueryParser return DisjunctionMaxQuery?
Date Mon, 28 Jun 2010 16:33:42 GMT

Why isn't there a parse function in MultiFieldQueryParser returning a 

Unless I got the whole concept wrong, if I search for "foo bar" in 2 
fields or more, the only difference between a BooleanQuery returned from 
MFQP and a DisjunctionMaxQuery the way it should be used for such a 
case, is in the way they implement scoring.

Meaning, MFQP could provide such a function just as easy (following is a 
quick untested draft):

   public static Query parse(Version matchVersion, String query, 
String[] fields, Analyzer analyzer) throws ParseException {
     if (fields.length > flags.length) // LUCENE-2518
       throw new IllegalArgumentException("fields.length > flags.length");
     DisjunctionMaxQuery dmQuery = new DisjunctionMaxQuery();
     for (int i = 0; i < fields.length; i++) {
       QueryParser qp = new QueryParser(matchVersion, fields[i], analyzer);
       Query q = qp.parse(query);
       if (q!=null && // q never null, just being defensive
           (!(q instanceof BooleanQuery) || 
((BooleanQuery)q).getClauses().length>0)) {
     return dmQuery;

Or couldn't it?


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

View raw message