Skip to content

A platform for community discussion. Free, open, simple.

FIX: Search topic title headline being truncated.

Guo Xiang Tand10d296e92aa
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=''<span class=\"#{HIGHLIGHT_CSS_CLASS}\">'', StopSel=''</span>'''
+ 'StartSel=''<span class=\"#{HIGHLIGHT_CSS_CLASS}\">'', StopSel=''</span>'', 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 <span class=\"#{Search::HIGHLIGHT_CSS_CLASS}\">search</span> <span class=\"#{Search::HIGHLIGHT_CSS_CLASS}\">term</span> 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