Skip to content

Instantly share code, notes, and snippets.

@mikebaldry
Created May 27, 2011 09:24
Show Gist options
  • Save mikebaldry/994924 to your computer and use it in GitHub Desktop.
Save mikebaldry/994924 to your computer and use it in GitHub Desktop.
TagCloud map/reduce Mongo Mapper
class TagCloud
MAP = <<-JS
function () {
this.tags.forEach(function (tag) {
emit(tag, 1);
});
}
JS
REDUCE = <<-JS
function (prev, current) {
var count = 0;
for (index in current) {
count += current[index];
}
return count;
}
JS
def self.build
Post.collection.map_reduce(MAP, REDUCE).find.to_a
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment