From c5e65cc6c89c108078c6a3a5bf70e0e998e7a8ec Mon Sep 17 00:00:00 2001 From: Sam Saffron Date: Fri, 19 Sep 2014 12:44:47 +1000 Subject: [PATCH] FEATURE: advanced category:NAME search operator --- lib/search.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/search.rb b/lib/search.rb index 60301ff3322..2d14b4c997e 100644 --- a/lib/search.rb +++ b/lib/search.rb @@ -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")