I want to boost a query in Lucene 7. In the previous versions (< 6) I was just using the setBoost(float boost) method. i.e.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With