better popular tag sorting that is not just alphabetical

master
Andrew Coleman 2009-03-22 23:29:23 -05:00
parent 4868084691
commit 4e7a5ce2bd
3 changed files with 6 additions and 6 deletions

View File

@ -30,9 +30,9 @@ class Album < ActiveRecord::Base
end
def self.popular_tags(limit = nil)
query = "SELECT tags.id, tags.name, count(*) AS count FROM albums_tags, tags, albums WHERE tags.id = tag_id AND albums_tags.album_id = albums.id GROUP BY tags.id, tags.name ORDER BY tags.name ASC"
query = "SELECT tags.id, tags.name, count(*) AS count FROM albums_tags, tags, albums WHERE tags.id = tag_id AND albums_tags.album_id = albums.id GROUP BY tags.id, tags.name ORDER BY count DESC"
query << " LIMIT #{limit}" unless limit.nil?
Tag.find_by_sql(query)
Tag.find_by_sql(query).sort { |a, b| a.name <=> b.name }
end
protected

View File

@ -35,9 +35,9 @@ class Page < ActiveRecord::Base
end
def self.popular_tags(limit = nil)
query = "SELECT tags.id, tags.name, count(*) AS count FROM pages_tags, tags, pages WHERE tags.id = tag_id AND pages_tags.page_id = pages.id GROUP BY tags.id, tags.name ORDER BY tags.name ASC"
query = "SELECT tags.id, tags.name, count(*) AS count FROM pages_tags, tags, pages WHERE tags.id = tag_id AND pages_tags.page_id = pages.id GROUP BY tags.id, tags.name ORDER BY count DESC"
query << " LIMIT #{limit}" unless limit.nil?
Tag.find_by_sql(query)
Tag.find_by_sql(query).sort { |a, b| a.name <=> b.name }
end
def cache_name

View File

@ -37,9 +37,9 @@ class Photo < ActiveRecord::Base
end
def self.popular_tags(limit = nil)
query = "SELECT tags.id, tags.name, count(*) AS count FROM photo_tags, tags, photos WHERE tags.id = tag_id AND photo_tags.photo_id = photos.id GROUP BY tags.id, tags.name ORDER BY tags.name ASC"
query = "SELECT tags.id, tags.name, count(*) AS count FROM photo_tags, tags, photos WHERE tags.id = tag_id AND photo_tags.photo_id = photos.id GROUP BY tags.id, tags.name ORDER BY count DESC"
query << " LIMIT #{limit}" unless limit.nil?
Tag.find_by_sql(query)
Tag.find_by_sql(query).sort { |a, b| a.name <=> b.name }
end
protected