better popular tag sorting that is not just alphabetical
parent
4868084691
commit
4e7a5ce2bd
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Reference in New Issue