Hi,
Why isn't there a parse function in MultiFieldQueryParser returning a
DisjunctionMaxQuery?
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)) {
dmQuery.add(q);
}
}
return dmQuery;
}
Or couldn't it?
Itamar.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]