Fork me on GitHub

taggregator by oddlyzen

Bad-ass tagging intelligence for your MongoMapper documents

Adds tagging with context and aggregation of tags for MongoMapper. Adds weight and distribution convenience methods to models in which it is included. Uses MongoDB's increment/decrement ($inc/$dec) to keep real-time counts of individual tags in context with optional type. Based on Mongoid Taggable With Context.

Taggregator is very easy to use. Just include the MongoMapper plugin in your model the normal way and call taggable, like so:

class Article
  include MongoMapper::Document
  plugin  MongoMapper::Plugins::Taggregator

  key :title, String
  key :body, String
  taggable :keywords
  taggable :ads, :separator => ','

a =

Tags are then set with a string by calling a.tags = 'space separated tags'. Tag separators default to a space character, but as you see in the above example, can be overridden for with any character or string of your choice. If we follow the lead of the example, we would set by calling = 'comma,separated,tags'. The call to taggable will also add the array representation of the taggable fields with context, accessible through a.tags_array, a.keywords_array, and a.ads_array. If you have an array of string tags and wish to set the tags array manually, you can (i.e., a.ads_array = ['xmas', 'shopping', 'books']). Just as setting the string will populate a.ads_array, setting the tags array will also populate the string representation of the tag list in context.

The call to taggable will also allow you to do some pretty cool stuff now. You can get all articles tags with a call to Article.tags and all tags (in the 'keywords' context) with Article.keywords. If you would like to get a list of all keywords with the keyword's associated frequency/weight, simply do something like:

Article.tags_with_weight_for :keywords
=> [["stocks", 4], ["finance", 4], ["banking", 3], ["bonds", 1]]

Development Dependencies

Taggregator development depends on the following gems:


Add Taggregator to your Gemfile:

gem 'taggregator'




Mark Coates


Mark Coates (


Release 0.1.1


You can download this project in either zip or tar formats.

You can also clone the project with Git by running:

$ git clone git://