tags:

views:

664

answers:

1

Hi,

Can I boost different fields in MultiFieldQueryParser with different factors? Also, what is the maximum boost factor value I can assign to a field?

Thanks a ton! Ed

+1  A: 

MultiFieldQueryParser has a constructor that accepts a map of boosts. You use it with something like this:

String[] fields = new String[] { "title", "keywords", "text" };
HashMap<String,Float> boosts = new HashMap<String,Float>();
boosts.put("title", 10);
boosts.put("keywords", 5);
MultiFieldQueryParser queryParser = new MultiFieldQueryParser(
    fields, 
    new StandardAnalyzer(),
    boosts
);

As for the maximum boost, I'm not sure, but you shouldn't think about boost in absolute terms anyway. Just use a ratio of boosts that makes sense. Also see this question.

itsadok
Hi,thanks for your answer....am using lucene.net version 2.0.0.4I dont see MultiFieldQueryParser constructor accepting boost values.MultiFieldQueryParser multiFieldQueryParser = new MultiFieldQueryParser(fields, _analyzer);May I know which Lucene version are u using?Thanks.
Ed
The boosts parameter was available only in Lucene 2.4. If you can't upgrade you might consider copying the code into your own MyMutliFieldQueryParser. It's not that much code.
itsadok
You may have to port the code from java... I couldn't find lucene.net's source code online (svn.apache.org is down ATM).
itsadok