Sha256: 5dafee144c209df716052f4b86777cd7cb1ac54d5f5df9dbfb3900f20ae1ca70
Contents?: true
Size: 674 Bytes
Versions: 13
Compression:
Stored size: 674 Bytes
Contents
// TODO: port it to map reduce function tagCloud(collection, q, limit) { var counts = db.eval( function(collection, q){ var counts = {}; 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 ); } } } ); return counts; }, 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
13 entries across 13 versions & 1 rubygems