mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
FEATURE: added status:noreplies and status:archived to advanced search
This commit is contained in:
parent
840b68003c
commit
cbc132eca9
3 changed files with 20 additions and 2 deletions
|
@ -2128,6 +2128,8 @@ en:
|
|||
`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
|
||||
`status:archived` Only show archived topics
|
||||
`status:noreplies` Show posts with a single participant
|
||||
`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.
|
||||
|
|
|
@ -142,6 +142,7 @@ class Search
|
|||
private
|
||||
|
||||
def process_advanced_search!(term)
|
||||
|
||||
term.to_s.split(/\s+/).map do |word|
|
||||
if word == 'status:open'
|
||||
@status = :open
|
||||
|
@ -149,6 +150,12 @@ class Search
|
|||
elsif word == 'status:closed'
|
||||
@status = :closed
|
||||
nil
|
||||
elsif word == 'status:archived'
|
||||
@status = :archived
|
||||
nil
|
||||
elsif word == 'status:noreplies'
|
||||
@no_replies = true
|
||||
nil
|
||||
elsif word == 'order:latest'
|
||||
@order = :latest
|
||||
nil
|
||||
|
@ -263,8 +270,14 @@ class Search
|
|||
|
||||
if @status == :open
|
||||
posts = posts.where('NOT topics.closed AND NOT topics.archived')
|
||||
elsif @status == :archived
|
||||
posts = posts.where('topics.archived')
|
||||
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
|
||||
|
||||
# If we have a search context, prioritize those posts first
|
||||
|
|
|
@ -319,8 +319,11 @@ describe Search do
|
|||
topic.closed = false
|
||||
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:noreplies').posts.length.should == 1
|
||||
|
||||
end
|
||||
|
||||
it 'can find by latest' do
|
||||
|
|
Loading…
Reference in a new issue