Rename @tags_all to @tags_count because that's how it's being used
Use a relation to build up the query from the common parts
Remove duplicate tags_count code
Merge pull request #312 from sferik/categorization

Clean up categorization method