Sha256: 8dc47b73eca45039eb1040b8a33dd5192d803acbe8cbd81ae72d1823057b7421
Contents?: true
Size: 729 Bytes
Versions: 2
Compression:
Stored size: 729 Bytes
Contents
// TODO: port it to map reduce function tagCloud(collection, q, limit) { var counter = function(collection, q){ var counts = {constructor: 0}; db[collection].find(q, {"tags":1}).limit(500).forEach( function(p){ if ( p.tags ){ for ( var i=0; i<p.tags.length; i++ ){ var name = p.tags[i]; counts[name] = 1 + ( counts[name] || 0 ); } } } ); if(counts["constructor"] == 0) { delete counts.constructor; } return counts; }; var counts = counter(collection, q); // maybe sort to by nice var sorted = []; for ( var tag in counts ){ sorted.push( { name : tag , count : counts[tag] } ) } return sorted.slice(0,limit||30); }
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
mongoid_ext-0.6.2 | lib/mongoid_ext/js/tag_cloud.js |
mongoid_ext-0.6.1 | lib/mongoid_ext/js/tag_cloud.js |