Did you ever want to put the instances of your domain classes into user-defined categories? Something like tags but more structured and maybe hierarchical?

Good news today: Grails has a plug-in for this purpose – it is called the taxonomy plug-in. The developers of this plug-in say that it allows you to apply arbitrary hierarchical categorisation (Taxons) to domain objects. Here is an example of the basic usage:

def book = Book.get(1) // Add the book to the Non-fiction > Autobiography category book.addToTaxonomy(['Non-fiction', 'Autobiography'])  def autobiographies = Book.findAllByTaxonomyFamily(     ['Non-fiction', 'Autobiography'] )

There is support for arbitrary nesting of Taxons (categories) within unlimited taxonomies, and taxonomies are domain class independent.

So the category „Local“ on Author can also be used on Book.

However, you can have different taxonomy graphs aside from the default one, so you might have a taxonomy graph „Location“ storing the names of states and cities, and another taxonomy graph „Company type“ – and objects having categories in both graphs.

Release 0.1 of the taxonomy plug-in is „alpha“ grade. It does not support polymorphism. So querying objects by taxonomy requires you to query the specific class type. This will be resolved in the next release. Also, it does not do caching so it isn’t going to be blazingly fast. Developers say that this will come soon.

Have fun and visit the plug-in page on grails.org.