Skip to content

Instantly share code, notes, and snippets.

@jeffdeville
Created October 21, 2010 20:05
Show Gist options
  • Save jeffdeville/639216 to your computer and use it in GitHub Desktop.
Save jeffdeville/639216 to your computer and use it in GitHub Desktop.
def self.get_potentials(interest_ids)
return {} if interest_ids.nil? ||interest_ids.empty?
map = <<-eos
function() {
for(var i in this.value.users) {
emit(this.value.users[i], 1);
}
};
eos
reduce = <<-eos
function(key, emits) {
var count = 0;
for(var i in emits) {
count += emits[i];
}
return count;
};
eos
users = InterestMap.collection.map_reduce(map, reduce,
{:query => {:_id => {:$in => interest_ids}} }).find().to_a
users.inject({}) do |h,user|
h[user["_id"].to_i] = user["value"]
h
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment