FEATURE: advanced category:NAME search operator

This commit is contained in:
Sam Saffron 2014-09-19 12:44:47 +10:00
parent 4e91059f89
commit c5e65cc6c8
1 changed files with 7 additions and 0 deletions

View File

@ -152,6 +152,9 @@ class Search
elsif word == 'order:latest'
@order = :latest
nil
elsif word =~ /category:(.+)/
@category_id = Category.find_by('name ilike ?', $1).try(:id)
nil
else
word
end
@ -277,6 +280,10 @@ class Search
end
if @category_id
posts = posts.where("topics.category_id = ?", @category_id)
end
if @order == :latest
if opts[:aggregate_search]
posts = posts.order("MAX(posts.created_at) DESC")