FEATURE: order:views order by views

This commit is contained in:
Sam 2014-10-18 15:38:58 +11:00
parent e6cc4cba8b
commit de71477405
2 changed files with 10 additions and 0 deletions

View file

@ -2125,6 +2125,7 @@ en:
search_help: | search_help: |
You may include special search operators: 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) `order:latest` Results will be ordered by last post time (as opposed to relevence)
`status:open` Only show open topics `status:open` Only show open topics
`status:closed` Only show closed topics `status:closed` Only show closed topics

View file

@ -159,6 +159,9 @@ class Search
elsif word == 'order:latest' elsif word == 'order:latest'
@order = :latest @order = :latest
nil nil
elsif word == 'order:views'
@order = :views
nil
elsif word =~ /category:(.+)/ elsif word =~ /category:(.+)/
@category_id = Category.find_by('name ilike ?', $1).try(:id) @category_id = Category.find_by('name ilike ?', $1).try(:id)
nil nil
@ -346,6 +349,12 @@ class Search
else else
posts = posts.order("posts.created_at DESC") posts = posts.order("posts.created_at DESC")
end end
elsif @order == :views
if opts[:aggregate_search]
posts = posts.order("MAX(topics.views) DESC")
else
posts = posts.order("topics.views DESC")
end
else else
posts = posts.order("TS_RANK_CD(TO_TSVECTOR(#{query_locale}, topics.title), #{ts_query}) DESC") posts = posts.order("TS_RANK_CD(TO_TSVECTOR(#{query_locale}, topics.title), #{ts_query}) DESC")