Skip to content

Commit

Permalink
FEATURE: advanced category:NAME search operator
Browse files Browse the repository at this point in the history
  • Loading branch information
SamSaffron committed Sep 19, 2014
1 parent 4e91059 commit c5e65cc
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ def process_advanced_search!(term)
elsif word == 'order:latest'
@order = :latest
nil
elsif word =~ /category:(.+)/
@category_id = Category.find_by('name ilike ?', $1).try(:id)
nil
else
word
end
Expand Down Expand Up @@ -277,6 +280,10 @@ def posts_query(limit, opts=nil)

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")
Expand Down

0 comments on commit c5e65cc

Please sign in to comment.