From 9a23a0bbbdb4f08902bd51015329b7d30ec59ed5 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 26 Jun 2015 17:36:28 +1000 Subject: [PATCH] FEATURE: topic:TOPIC_ID to search within topic --- lib/search.rb | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/search.rb b/lib/search.rb index a2a32c0e919..1395cb7fd34 100644 --- a/lib/search.rb +++ b/lib/search.rb @@ -95,18 +95,18 @@ class Search end def initialize(term, opts=nil) - term = process_advanced_search!(term) - if term.present? - @term = Search.prepare_data(term.to_s) - @original_term = PG::Connection.escape_string(@term) - end - @opts = opts || {} @guardian = @opts[:guardian] || Guardian.new @search_context = @opts[:search_context] @include_blurbs = @opts[:include_blurbs] || false @limit = Search.per_facet + term = process_advanced_search!(term) + if term.present? + @term = Search.prepare_data(term.to_s) + @original_term = PG::Connection.escape_string(@term) + end + if @search_pms && @guardian.user @opts[:type_filter] = "private_messages" @search_context = @guardian.user @@ -252,6 +252,15 @@ class Search if word == 'order:latest' @order = :latest nil + elsif word =~ /topic:(\d+)/ + topic_id = $1.to_i + if topic_id > 1 + topic = Topic.find_by(id: topic_id) + if @guardian.can_see?(topic) + @search_context = topic + end + end + nil elsif word == 'order:views' @order = :views nil