You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Raghavendra Prabhu <rr...@gmail.com> on 2006/03/08 11:05:05 UTC
MuliField Query Parser
Hi
I need different boosts for fields which we define in multifield query
parser
How can this be accomplished??
Rgds
Prabhu
Re: MuliField Query Parser
Posted by Rainer Dollinger <do...@webdynamite.com>.
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