Skip to content

Commit

Permalink
Use the most recent entries in case of egality, for more predictability
Browse files Browse the repository at this point in the history
  • Loading branch information
Fantomas42 committed Mar 25, 2017
1 parent 4d7c657 commit 7cae1ea
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
3 changes: 1 addition & 2 deletions zinnia/comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ def compute_related(self, object_id, score=pearson_score):
object_related[o_id] = score(object_vector, o_vector)
except ZeroDivisionError:
pass

related = sorted(object_related.items(),
key=lambda k_v: k_v[1], reverse=True)
key=lambda k_v: (k_v[1], k_v[0]), reverse=True)
return related

@cached_property
Expand Down
2 changes: 1 addition & 1 deletion zinnia/tests/test_templatetags.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def test_get_similar_entries(self):
context = get_similar_entries(source_context, 3,
'custom_template.html')
self.assertEqual(len(context['entries']), 2)
self.assertEqual(context['entries'][0].pk, second_entry.pk)
self.assertEqual(context['entries'][0].pk, third_entry.pk)
self.assertEqual(context['template'], 'custom_template.html')
with self.assertNumQueries(0):
context = get_similar_entries(source_context, 3)
Expand Down

0 comments on commit 7cae1ea

Please sign in to comment.