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.
This commit is contained in:
Guo Xiang Tan 2020-12-21 14:42:03 +08:00 committed by Alan Guo Xiang Tan
parent 8336c2235e
commit d10d296e92
2 changed files with 14 additions and 1 deletions

View File

@ -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},

View File

@ -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