用Lucene提升新文档 [英] Boost fresh documents with Lucene
问题描述
Lucene是否提供了一种提升新文档的方法?
Does Lucene provide a means to boost fresh documents?
例如,假设Lucene文档包含日期字段。是否有可能在没有用户改变她的查询的情况下,以更高的分数呈现最新的文档?
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.
推荐答案
将文档放入索引时使用Document.setBoost(浮点值)。
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.
例如,从第1天文档的提升值0开始。每天,将提升增加1.这是一个浮动值,每年增加365将持续很长时间。
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.
这篇关于用Lucene提升新文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!