lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Itamar Syn-Hershko <ita...@code972.com>
Subject Re: Make MultiFieldQueryParser return DisjunctionMaxQuery?
Date Tue, 29 Jun 2010 21:43:13 GMT
Did some testing, seems like this is a valid approach (ehm, ignore the 
lines marked with LUCENE-2518).

Should I create a JIRA issue for this then?

Itamar.

On 28/6/2010 7:33 PM, Itamar Syn-Hershko wrote:
> 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: dev-unsubscribe@lucene.apache.org
> For additional commands, e-mail: dev-help@lucene.apache.org
>
>
>

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


Mime
View raw message