FIX: Ignore empty search terms in topic queries

FIX: Ignore empty search terms in topic queries

Previously an empty search term would cause an invalid tsquery, and led to a 500 error. Now an empty string will be ignored.

diff --git a/lib/topic_query.rb b/lib/topic_query.rb
index 4670ae6..e94b03a 100644
--- a/lib/topic_query.rb
+++ b/lib/topic_query.rb
@@ -748,7 +748,7 @@ class TopicQuery
       result = result.where('topics.id in (?)', options[:topic_ids]).references(:topics)
     end
 
-    if search = options[:search]
+    if search = options[:search].presence
       result = result.where("topics.id in (select pp.topic_id from post_search_data pd join posts pp on pp.id = pd.post_id where pd.search_data @@ #{Search.ts_query(term: search.to_s)})")
     end
 
diff --git a/spec/requests/list_controller_spec.rb b/spec/requests/list_controller_spec.rb
index 0de5c88..349da25 100644
--- a/spec/requests/list_controller_spec.rb
+++ b/spec/requests/list_controller_spec.rb
@@ -52,6 +52,9 @@ RSpec.describe ListController do
 
       get "/latest.json?page=2147483647"
       expect(response.status).to eq(200)
+
+      get "/latest?search="
+      expect(response.status).to eq(200)
     end
 
     (Discourse.anonymous_filters - [:categories]).each do |filter|

GitHub sha: 2f964741