开发者

How to apply default sorting in lucene on equal scores?

开发者 https://www.devze.com 2022-12-11 09:17 出处:网络
Good day, If I have for example the documents whi开发者_C百科ch have the following fields Person_name - Birthday

Good day,

If I have for example the documents whi开发者_C百科ch have the following fields

Person_name - Birthday
Jordan - 2009-06-15
Marc - 2009-01-01
Marcos - 2009-01-01
Marcissh_something_something - 2009-06-15
Marcos - 2009-12-31

And upon searching for Person_name:Marc* I got the following scores (scores here are hypothetical)

Person_name - Birthday - Score
Jordan - 2009-06-15 - 0.0
Marc - 2009-01-01 - 1.0
Marcos - 2009-01-01 - 0.8
Marcissh_something_something - 2009-06-15 - 0.1
Marcos - 2009-12-31 - 0.8

How can I retrieve the result such that the result is first sorted by relevancy, and then assuming same relevancy (score) sort by birthday descendingly....such that the result is

Person_name - Birthday - Score
Marc - 2009-01-01 - 1.0
Marcos - 2009-12-31 - 0.8
Marcos - 2009-01-01 - 0.8
Marcissh_something_something - 2009-06-15 - 0.1

Thanks


I was going to recommend a ScoreDocComparator, but I see it is deprecated now. You can use a FieldComparator. You need to create a TopFieldCollector and define its Sort according to your wishes. I believe this is rather new, as I could not find a good example.


Try to examine the search results and then sort those with equal score yourself. You can use a comparator for this which compares the score and then the natural fields of the search results.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号