Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boost fresh documents with Lucene

Does Lucene provide a means to boost fresh documents?

For example suppose that the Lucene document includes a date field. Is it possible, without having the user to alter her query anyhow, to present the most recent documents with a higher score?

I do not want to resort to a coarse "sort by date" solution as it will completely cancel the scoring algorithm.

like image 401
yannisf Avatar asked Jan 18 '11 13:01

yannisf


2 Answers

You can see Lucene in Action. In the second edition, pg. 187 they give a way to do it. Basically, you will want to write your own query which extends CustomScoreQuery, and adds a boost.

like image 192
Xodarap Avatar answered Oct 10 '22 20:10

Xodarap


Use Document.setBoost(float value) when putting documents into the index.

You can either constantly re-adjust the value on existing documents, OR have a float value that increments with date, so that you only need to apply it to the time that documents are inserted.

For example, start with a boost value of 0 for day 1 documents. Each day, increment the boost by 1. It's a float value, incrementing by 365 each year will last a long time.

You may have to experiment with the strength of the boost to get the effect you want.

like image 24
rfeak Avatar answered Oct 10 '22 20:10

rfeak