tag autocomplete and better browsing

This commit is contained in:
Kyle Drake 2014-07-31 15:25:08 -07:00
parent 581398f826
commit 1ac9cdf606
9 changed files with 1956 additions and 96 deletions

View file

@ -11,4 +11,15 @@ class Tag < Sequel::Model
def self.create_unless_exists(name)
dataset.filter(name: name).first || create(name: name)
end
def self.suggestions(name, limit=3)
Tag.filter(name: /^#{name}/).
order(:name).
limit(limit).
all
end
def self.popular_names(limit=10)
DB["select tags.name,count(*) as c from sites_tags inner join tags on tags.id=sites_tags.tag_id where tags.name != '' group by tags.name having count(*) > 1 order by c desc LIMIT ?", limit].all
end
end