FEATURE: added status:noreplies and status:archived to advanced search

This commit is contained in:
Sam 2014-10-18 14:54:11 +11:00
parent 840b68003c
commit cbc132eca9
3 changed files with 20 additions and 2 deletions

View file

@ -2128,6 +2128,8 @@ en:
`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
`status:archived` Only show archived topics
`status:noreplies` Show posts with a single participant
`category:foo` Only show topics in the category `foo` `category:foo` Only show topics in the category `foo`
Example: `bears category:test status:open order:latest` will search for topics in the category bears that are not closed or archived ordered by last post date. Example: `bears category:test status:open order:latest` will search for topics in the category bears that are not closed or archived ordered by last post date.

View file

@ -142,6 +142,7 @@ class Search
private private
def process_advanced_search!(term) def process_advanced_search!(term)
term.to_s.split(/\s+/).map do |word| term.to_s.split(/\s+/).map do |word|
if word == 'status:open' if word == 'status:open'
@status = :open @status = :open
@ -149,6 +150,12 @@ class Search
elsif word == 'status:closed' elsif word == 'status:closed'
@status = :closed @status = :closed
nil nil
elsif word == 'status:archived'
@status = :archived
nil
elsif word == 'status:noreplies'
@no_replies = true
nil
elsif word == 'order:latest' elsif word == 'order:latest'
@order = :latest @order = :latest
nil nil
@ -263,8 +270,14 @@ class Search
if @status == :open if @status == :open
posts = posts.where('NOT topics.closed AND NOT topics.archived') posts = posts.where('NOT topics.closed AND NOT topics.archived')
elsif @status == :archived
posts = posts.where('topics.archived')
elsif @status == :closed elsif @status == :closed
posts = posts.where('topics.closed OR topics.archived') posts = posts.where('topics.closed')
end
if @no_replies
posts = posts.where("topics.featured_user1_id IS NULL AND topics.last_post_user_id = topics.user_id")
end end
# If we have a search context, prioritize those posts first # If we have a search context, prioritize those posts first

View file

@ -319,8 +319,11 @@ describe Search do
topic.closed = false topic.closed = false
topic.save topic.save
Search.execute('test status:closed').posts.length.should == 1 Search.execute('test status:archived').posts.length.should == 1
Search.execute('test status:open').posts.length.should == 0 Search.execute('test status:open').posts.length.should == 0
Search.execute('test status:noreplies').posts.length.should == 1
end end
it 'can find by latest' do it 'can find by latest' do