FEATURE: Log only topic/post search queries in search log (#14994)
This commit is contained in:
parent
db24c9b94e
commit
20f5474be9
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue