lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rainer Dollinger <>
Subject Re: MuliField Query Parser
Date Wed, 08 Mar 2006 10:57:25 GMT
You could try to inherit from MultiFieldQueryParser:

public class BoostableMultiFieldQueryParser extends MultiFieldQueryParser {

    // TODO: add constructors of super class

    public static Query parse(String query, String[] fields,
            BooleanClause.Occur[] flags,Analyzer analyzer, float[]
boosts) throws ParseException {
          if (fields.length != flags.length)
            throw new IllegalArgumentException("fields.length !=
          BooleanQuery bQuery = new BooleanQuery();
          for (int i = 0; i < fields.length; i++) {
            QueryParser qp = new QueryParser(fields[i], analyzer);
            Query q = qp.parse(query);

            // ATTENTION: the only new line !!!

            bQuery.add(q, flags[i]);
          return bQuery;

I copied the code of method parse(String, String, BooleanClause.Occur[],
Analyzer) and added the parameter float[] boosts.
I marked the only line I have inserted.
You have to add the constructors from the super class to get the class

I did'nt have the time to test this idea, please post a reply if it
works, if you try this.


Raghavendra Prabhu wrote:
> Hi
> I need different boosts for fields which we define in multifield query
> parser
> How can this be accomplished??
> Rgds
> Prabhu

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

View raw message