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

Version Path
mongomapper_ext-0.5.2 lib/mongomapper_ext/js/tag_cloud.js
mongomapper_ext-0.5.1 lib/mongomapper_ext/js/tag_cloud.js
mongomapper_ext-0.5.0 lib/mongomapper_ext/js/tag_cloud.js
mongomapper_ext-0.4.0 lib/mongomapper_ext/js/tag_cloud.js
mongomapper_ext-0.3.0 lib/mongomapper_ext/js/tag_cloud.js
mongomapper_ext-0.2.4 lib/mongomapper_ext/js/tag_cloud.js
mongomapper_ext-0.2.3 lib/mongomapper_ext/js/tag_cloud.js
mongomapper_ext-0.2.2 lib/mongomapper_ext/js/tag_cloud.js
mongomapper_ext-0.2.1 lib/mongomapper_ext/js/tag_cloud.js
mongomapper_ext-0.2.0 lib/mongomapper_ext/js/tag_cloud.js
mongomapper_ext-0.1.5 lib/mongomapper_ext/js/tag_cloud.js
mongomapper_ext-0.1.4 lib/mongomapper_ext/js/tag_cloud.js
mongomapper_ext-0.1.3 lib/mongomapper_ext/js/tag_cloud.js