diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index bfe932db5..75857de0e 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -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. diff --git a/lib/search.rb b/lib/search.rb index c1267d8c0..c47bcd2bb 100644 --- a/lib/search.rb +++ b/lib/search.rb @@ -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 diff --git a/spec/components/search_spec.rb b/spec/components/search_spec.rb index f47698c4c..02cf69134 100644 --- a/spec/components/search_spec.rb +++ b/spec/components/search_spec.rb @@ -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