lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rainer Dollinger <dollin...@webdynamite.com>
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 !=
flags.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 !!!
            q.setBoost(boost[i]);

            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
compiled.

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

Rainer



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: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message