FIX: Topic.similar_to results in invalid query for certain locales. (#14497)

For `zh_CN`, we use the `cppjieba_rb` gem to remove stop words so
calling `Search.prepare_data` may result in an empty string.
This commit is contained in:
Alan Guo Xiang Tan
2021-10-04 11:40:22 +08:00
committed by GitHub
parent aba08d1929
commit 4cade9d7f6
2 changed files with 10 additions and 4 deletions

View File

@@ -581,11 +581,11 @@ class Topic < ActiveRecord::Base
def self.similar_to(title, raw, user = nil)
return [] if title.blank?
raw = raw.presence || ""
search_data = Search.prepare_data(title.strip)
tsquery = Search.set_tsquery_weight_filter(
Search.prepare_data(title.strip),
'A'
)
return [] if search_data.blank?
tsquery = Search.set_tsquery_weight_filter(search_data, 'A')
if raw.present?
cooked = SearchIndexer::HtmlScrubber.scrub(