简体   繁体   中英

How do I boost queries in Lucene 7?

I want to boost a query in Lucene 7. In the previous versions (< 6) I was just using the setBoost(float boost) method. ie

TermQuery termQuery = new TermQuery(new Term("field", "value"));
termQuery.setBoost(2);

In Lucene 7 there is only a method that contains the boost as a parameter:

public Weight createWeight(IndexSearcher searcher,
                       boolean needsScores,
                       float boost)

which isn't the method responsible for the boost! Do you know how to apply the boosting to the queries?

All queries are now immutable, which also extends to boosts, per LUCENE-6590 . As such, to apply boosts you would use a BoostQuery to wrap the query. Like this:

Query termQuery = new TermQuery(new Term("field", "value"));
Query boostedTermQuery = new BoostQuery(termQuery, 2);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM