mirror of
https://github.com/discourse/discourse.git
synced 2025-04-02 00:50:11 +08:00
FEATURE: advanced category:NAME search operator
This commit is contained in:
parent
4e91059f89
commit
c5e65cc6c8
@ -152,6 +152,9 @@ class Search
|
|||||||
elsif word == 'order:latest'
|
elsif word == 'order:latest'
|
||||||
@order = :latest
|
@order = :latest
|
||||||
nil
|
nil
|
||||||
|
elsif word =~ /category:(.+)/
|
||||||
|
@category_id = Category.find_by('name ilike ?', $1).try(:id)
|
||||||
|
nil
|
||||||
else
|
else
|
||||||
word
|
word
|
||||||
end
|
end
|
||||||
@ -277,6 +280,10 @@ class Search
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if @category_id
|
||||||
|
posts = posts.where("topics.category_id = ?", @category_id)
|
||||||
|
end
|
||||||
|
|
||||||
if @order == :latest
|
if @order == :latest
|
||||||
if opts[:aggregate_search]
|
if opts[:aggregate_search]
|
||||||
posts = posts.order("MAX(posts.created_at) DESC")
|
posts = posts.order("MAX(posts.created_at) DESC")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user