問題描述
Lucene 是否提供了一種增加新文檔的方法?
Does Lucene provide a means to boost fresh documents?
例如,假設 Lucene 文檔包含一個日期字段.是否有可能在不讓用戶改變她的查詢的情況下,以更高的分數(shù)呈現(xiàn)最新的文檔?
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.
您可以不斷地重新調整現(xiàn)有文檔上的值,或者擁有一個隨日期遞增的浮點值,這樣您只需將其應用于插入文檔的時間.
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 會持續(xù)很長時間.
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 提升新文檔的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!