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

This commit is contained in:
Penar Musaraj 2021-11-17 20:21:12 -05:00 committed by GitHub
parent db24c9b94e
commit 20f5474be9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -252,7 +252,7 @@ class Search
# Query a term # Query a term
def execute(readonly_mode: Discourse.readonly_mode?) 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( status, search_log_id = SearchLog.log(
term: @term, term: @term,
search_type: @opts[:search_type], search_type: @opts[:search_type],
@ -1294,4 +1294,10 @@ class Search
end end
end end
def log_query?(readonly_mode)
SiteSetting.log_search_queries? &&
@opts[:search_type].present? &&
!readonly_mode &&
@opts[:type_filter] != "exclude_topics"
end
end end

View File

@ -231,6 +231,13 @@ describe SearchController do
expect(SearchLog.where(term: 'wookie')).to be_blank expect(SearchLog.where(term: 'wookie')).to be_blank
end 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 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 } get "/search/query.json", params: { term: "in:first", type_filter: "topic", search_for_id: true }
expect(response.status).to eq(200) expect(response.status).to eq(200)