mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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:
parent
aba08d1929
commit
4cade9d7f6
@ -581,11 +581,11 @@ class Topic < ActiveRecord::Base
|
|||||||
def self.similar_to(title, raw, user = nil)
|
def self.similar_to(title, raw, user = nil)
|
||||||
return [] if title.blank?
|
return [] if title.blank?
|
||||||
raw = raw.presence || ""
|
raw = raw.presence || ""
|
||||||
|
search_data = Search.prepare_data(title.strip)
|
||||||
|
|
||||||
tsquery = Search.set_tsquery_weight_filter(
|
return [] if search_data.blank?
|
||||||
Search.prepare_data(title.strip),
|
|
||||||
'A'
|
tsquery = Search.set_tsquery_weight_filter(search_data, 'A')
|
||||||
)
|
|
||||||
|
|
||||||
if raw.present?
|
if raw.present?
|
||||||
cooked = SearchIndexer::HtmlScrubber.scrub(
|
cooked = SearchIndexer::HtmlScrubber.scrub(
|
||||||
|
@ -540,6 +540,12 @@ describe Topic do
|
|||||||
expect(Topic.similar_to('some title', 'https://discourse.org/#INCORRECT#URI')).to be_empty
|
expect(Topic.similar_to('some title', 'https://discourse.org/#INCORRECT#URI')).to be_empty
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'does not result in invalid statement when title is all stopwords for zh_CN' do
|
||||||
|
SiteSetting.default_locale = "zh_CN"
|
||||||
|
|
||||||
|
expect(Topic.similar_to("怎么上自己的", '')).to eq([])
|
||||||
|
end
|
||||||
|
|
||||||
context 'with a similar topic' do
|
context 'with a similar topic' do
|
||||||
fab!(:post) {
|
fab!(:post) {
|
||||||
SearchIndexer.enable
|
SearchIndexer.enable
|
||||||
|
Loading…
Reference in New Issue
Block a user