Created
October 21, 2010 20:03
-
-
Save jeffdeville/639210 to your computer and use it in GitHub Desktop.
Map User/Interests to Interest/Users
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.update_map | |
map = 'function() {' + | |
'for (var i in this.interests) {' + | |
'if (this.interests[i]._id != null) {' + | |
'emit(this.interests[i]._id, {"users": this.facebook_id, "count": 1});' + | |
'}' + | |
'}' + | |
'}'; | |
reduce = 'function(key, emits) {' + | |
'var all_users = Array(); var count = 0;' + | |
'for(var i in emits) {' + | |
'all_users = all_users.concat(emits[i].users);' + | |
'count += emits[i].count;' + | |
'}' + | |
'return {"users": all_users, "count": count};}'; | |
User.collection.map_reduce(map, reduce,{:query => {:is_user => true}, :out => "interest_maps"}) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment