From 164a49c84ba819fae7e75586b32a0d963a9f62f9 Mon Sep 17 00:00:00 2001 From: r888888888 Date: Sat, 24 Sep 2016 03:59:10 -0700 Subject: [PATCH] fix sorting of post vote similarity algo --- app/logical/post_vote_similarity.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/logical/post_vote_similarity.rb b/app/logical/post_vote_similarity.rb index 761a4879e..0d74a43a4 100644 --- a/app/logical/post_vote_similarity.rb +++ b/app/logical/post_vote_similarity.rb @@ -25,17 +25,17 @@ class PostVoteSimilarity # returns user ids with strong positive correlation def calculate_positive(limit = 10) posts0 = PostVote.positive_post_ids(user_id) - set = SortedSet.new + set = [] PostVote.positive_user_ids.each do |uid| posts1 = PostVote.positive_post_ids(uid) score = calculate_with_cosine(posts0, posts1) if score >= THRESHOLD - set.add(Element.new(uid, score)) + set << Element.new(uid, score) end end - set.first(limit) + set.sort.reverse.first(limit) end def calculate_with_cosine(posts0, posts1)