fix sorting of post vote similarity algo
This commit is contained in:
@@ -25,17 +25,17 @@ class PostVoteSimilarity
|
|||||||
# returns user ids with strong positive correlation
|
# returns user ids with strong positive correlation
|
||||||
def calculate_positive(limit = 10)
|
def calculate_positive(limit = 10)
|
||||||
posts0 = PostVote.positive_post_ids(user_id)
|
posts0 = PostVote.positive_post_ids(user_id)
|
||||||
set = SortedSet.new
|
set = []
|
||||||
|
|
||||||
PostVote.positive_user_ids.each do |uid|
|
PostVote.positive_user_ids.each do |uid|
|
||||||
posts1 = PostVote.positive_post_ids(uid)
|
posts1 = PostVote.positive_post_ids(uid)
|
||||||
score = calculate_with_cosine(posts0, posts1)
|
score = calculate_with_cosine(posts0, posts1)
|
||||||
if score >= THRESHOLD
|
if score >= THRESHOLD
|
||||||
set.add(Element.new(uid, score))
|
set << Element.new(uid, score)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
set.first(limit)
|
set.sort.reverse.first(limit)
|
||||||
end
|
end
|
||||||
|
|
||||||
def calculate_with_cosine(posts0, posts1)
|
def calculate_with_cosine(posts0, posts1)
|
||||||
|
|||||||
Reference in New Issue
Block a user