Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: Log only topic/post search queries in search log (#14994)

Penar Musaraj20f5474be965
diff --git a/lib/search.rb b/lib/search.rb
index def3be0fd72..6230955b6a9 100644
--- a/lib/search.rb
+++ b/lib/search.rb
@@ -252,7 +252,7 @@ class Search
# Query a term
def execute(readonly_mode: Discourse.readonly_mode?)
- if SiteSetting.log_search_queries? && @opts[:search_type].present? && !readonly_mode
+ if log_query?(readonly_mode)
status, search_log_id = SearchLog.log(
term: @term,
search_type: @opts[:search_type],
@@ -1294,4 +1294,10 @@ class Search
end
end
+ def log_query?(readonly_mode)
+ SiteSetting.log_search_queries? &&
+ @opts[:search_type].present? &&
+ !readonly_mode &&
+ @opts[:type_filter] != "exclude_topics"
+ end
end
diff --git a/spec/requests/search_controller_spec.rb b/spec/requests/search_controller_spec.rb
index be85a71a354..a17f7d3aebb 100644
--- a/spec/requests/search_controller_spec.rb
+++ b/spec/requests/search_controller_spec.rb
@@ -231,6 +231,13 @@ describe SearchController do
expect(SearchLog.where(term: 'wookie')).to be_blank
end
+ it "doesn't log when filtering by exclude_topics" do
+ SiteSetting.log_search_queries = true
+ get "/search/query.json", params: { term: 'boop', type_filter: 'exclude_topics' }
+ expect(response.status).to eq(200)
+ expect(SearchLog.where(term: 'boop')).to be_blank
+ end
+
it "does not raise 500 with an empty term" do
get "/search/query.json", params: { term: "in:first", type_filter: "topic", search_for_id: true }
expect(response.status).to eq(200)