使用 Lucene 提升新文档

2022-01-15 00:00:00 lucene java information-retrieval

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(float value).

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 开始.每天,boost 递增 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.

相关文章