Similarity
class and using the index statistics that Lucene saves. Documents can also be assigned a static score to denote their importance in the overall corpus, irrespective of the query that is being executed, e.g their popularity, ratings or PageRank.
Prior to Lucene 4.0, you could assign a static score to a document by calling
document.setBoost
. Internally, the boost was applied to every field of the document, by multiplying the field's boost factor with the document's. However, as explained here, this has never worked correctly and depending on the type of query executed, might not affect the document's rank at all.
With the addition of DocValues to Lucene, boosting documents is as easy as adding a
NumericDocValuesField
and use it in a CustomScoreQuery
, which multiplies the computed score by the value of the 'boost' field. The code example below illustrates how to achieve that:
// add two documents to the index Document doc = new Document(); doc.add(new TextField("f", "test document", Store.NO)); doc.add(new NumericDocValuesField("boost", 1L)); writer.addDocument(doc); doc = new Document(); doc.add(new TextField("f", "test document", Store.NO)); doc.add(new NumericDocValuesField("boost", 2L)); writer.addDocument(doc); // search for 'test' while boosting by field 'boost' Query baseQuery = new TermQuery(new Term("f", "test")); Query boostQuery = new FunctionQuery(new LongFieldSource("boost")); Query q = new CustomScoreQuery(baseQuery, boostQuery); searcher.search(q, 10);
The new Expressions module can also be used for boosting documents by writing a simple formula, as depicted below. While it's more verbose than using
CustomScoreQuery
, it makes boosting by computing more complex formulas trivial, e.g. sqrt(_score) + ln(boost)
.
Expression expr = JavascriptCompiler.compile("_score * boost"); SimpleBindings bindings = new SimpleBindings(); bindings.add(new SortField("_score", SortField.Type.SCORE)); bindings.add(new SortField("boost", SortField.Type.LONG)); Sort sort = new Sort(expr.getSortField(bindings, true)); searcher.search(baseQuery, null, 10, sort);
Now that Lucene allows updating
NumericDocValuesFields
without re-indexing the documents, you can incorporate frequently changing fields (popularity, ratings, price, last-modified time...) in the boosting factor without re-indexing the document every time any one of them changes.
Is this boosting similar to Solr eDismax's boost parameter?
ReplyDeleteYou saved my day! Thanks a lot for the post!
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteBut you can also boost just for gun attachments or titles/emblems or pro perks. This is generally done in a boosting lobby. Again, it is free for all. Most people get a full game Think its 8 players of people who know its a boosting lobby and they all get a partner and boost.
ReplyDeleterealm royale boost
Thanks for writing such great texts. It's great to read. A lot of good news in this post.
ReplyDeletehttps://eloboost24.eu/marketplace