mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-17 19:12:37 -05:00
FEATURE: order:views order by views
This commit is contained in:
parent
e6cc4cba8b
commit
de71477405
2 changed files with 10 additions and 0 deletions
|
@ -2125,6 +2125,7 @@ en:
|
|||
search_help: |
|
||||
You may include special search operators:
|
||||
|
||||
`order:views` Results will be ordered by view count (as opposed to relevence)
|
||||
`order:latest` Results will be ordered by last post time (as opposed to relevence)
|
||||
`status:open` Only show open topics
|
||||
`status:closed` Only show closed topics
|
||||
|
|
|
@ -159,6 +159,9 @@ class Search
|
|||
elsif word == 'order:latest'
|
||||
@order = :latest
|
||||
nil
|
||||
elsif word == 'order:views'
|
||||
@order = :views
|
||||
nil
|
||||
elsif word =~ /category:(.+)/
|
||||
@category_id = Category.find_by('name ilike ?', $1).try(:id)
|
||||
nil
|
||||
|
@ -346,6 +349,12 @@ class Search
|
|||
else
|
||||
posts = posts.order("posts.created_at DESC")
|
||||
end
|
||||
elsif @order == :views
|
||||
if opts[:aggregate_search]
|
||||
posts = posts.order("MAX(topics.views) DESC")
|
||||
else
|
||||
posts = posts.order("topics.views DESC")
|
||||
end
|
||||
else
|
||||
posts = posts.order("TS_RANK_CD(TO_TSVECTOR(#{query_locale}, topics.title), #{ts_query}) DESC")
|
||||
|
||||
|
|
Loading…
Reference in a new issue