views:

250

answers:

2

Good day,

If I have for example the documents which 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

+1  A: 

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.

Aaron Digulla
+1  A: 

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.

Yuval F
Since I'm using lucene 2.4.1, I'll probably go with ScoreDocComparator...but how do I use it exactly? :-)
Franz See
In that case, please see my answer to:http://stackoverflow.com/questions/8517/lucene-exact-ordering
Yuval F