Boost factor in MultiFieldQueryParser

不问归期 提交于 2020-01-01 04:53:10

问题


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:


MultiFieldQueryParser has a [constructor][1] 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.

[1]: https://lucene.apache.org/core/4_4_0/queryparser/org/apache/lucene/queryparser/classic/MultiFieldQueryParser.html#MultiFieldQueryParser(org.apache.lucene.util.Version, java.lang.String[], org.apache.lucene.analysis.Analyzer, java.util.Map)



来源:https://stackoverflow.com/questions/551724/boost-factor-in-multifieldqueryparser

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!