Skip to content

Instantly share code, notes, and snippets.

@jeffdeville
Created September 19, 2010 02:32
Show Gist options
  • Save jeffdeville/586302 to your computer and use it in GitHub Desktop.
Save jeffdeville/586302 to your computer and use it in GitHub Desktop.
def dopplegangers()
raise StandardError.new("insufficient interests") unless interests.size >= MINIMUM_INTERESTS
usr_ints = interests.collect { |c| c.facebook_id }
matches = User.collection.find({
:facebook_id => {"$ne" => facebook_id}, #don't use current user
:access_token => {"$ne" => nil}, # access_token = activeuser
"interests.facebook_id" => {"$in" => usr_ints}}, # load all where at least 1 interest shared
{:fields => [:facebook_id, :interests]}).to_a
matches.each {|match| match[:score] = calculate_score(match) }
matches.sort{|x,y| y[:score] <=> x[:score]}
end
# Similarity Score Math (for now)
# num_shared_interests / (num_interests_for_user_1 + num_interests_for_user_2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment