Boost fresh documents with Lucene

╄→гoц情女王★ 提交于 2019-11-30 04:55:28

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/4724451/boost-fresh-documents-with-lucene

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!