Boost factor in MultiFieldQueryParser

后端 未结 1 576
忘了有多久
忘了有多久 2021-02-15 02:51

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条回答
  •  你的背包
    2021-02-15 03:13

    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 boosts = new HashMap();
    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)

    0 讨论(0)
提交回复
热议问题