Fix Errors on JRuby and PostgreSQL when searching tag
On JRuby and PosgreSQL, some complex statements do not work well
because of the restriction where distinct and order clause needs that the columns which is used in them in select clause.