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.
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.
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.
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