From d10d296e92aa039a4c7320875e2bc0ffdd815b41 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Mon, 21 Dec 2020 14:42:03 +0800 Subject: [PATCH] FIX: Search topic title headline being truncated. Need to apply the `HighlightAll` option in order to avoid topic titles from truncated in headlines when displaying search results. --- lib/search.rb | 2 +- spec/components/search_spec.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/search.rb b/lib/search.rb index 0b3b71003a0..90de3f7c6a0 100644 --- a/lib/search.rb +++ b/lib/search.rb @@ -1279,7 +1279,7 @@ class Search #{ts_config}, t1.fancy_title, PLAINTO_TSQUERY(#{ts_config}, '#{search_term}'), - 'StartSel='''', StopSel=''''' + 'StartSel='''', StopSel='''', HighlightAll=true' ) AS topic_title_headline", "TS_HEADLINE( #{ts_config}, diff --git a/spec/components/search_spec.rb b/spec/components/search_spec.rb index 5c8c19607db..b34e2c40807 100644 --- a/spec/components/search_spec.rb +++ b/spec/components/search_spec.rb @@ -542,6 +542,19 @@ describe Search do expect(post.headline.include?('elephant')).to eq(false) end + it "does not truncate topic title when applying highlights" do + SiteSetting.use_pg_headlines_for_excerpt = true + + topic = reply.topic + topic.update!(title: "#{'very ' * 7}long topic title with our search term in the middle of the title") + + result = Search.execute('search term') + + expect(result.posts.first.topic_title_headline).to eq(<<~TITLE.chomp) + Very very very very very very very long topic title with our search term in the middle of the title + TITLE + end + it "limits the search headline to #{Search::GroupedSearchResults::BLURB_LENGTH} characters" do SiteSetting.use_pg_headlines_for_excerpt = true