Commit bc3603b8 authored by Dylan Griffith's avatar Dylan Griffith

Fix regression in FOSS for search issue description highlight

This fixes https://gitlab.com/gitlab-org/gitlab/-/issues/254840

The `#use_elasticsearch?` method is not defined in FOSS so we cannot
refer to it. As such the easiest way to handle this is to move the logic
into a helper and override in EE.
parent 7ccf2b7b
......@@ -294,6 +294,11 @@ module SearchHelper
sanitize(html, tags: %w(a p ol ul li pre code))
end
# _search_highlight is used in EE override
def highlight_and_truncate_issue(issue, search_term, _search_highlight)
simple_search_highlight_and_truncate(issue.description, search_term, highlighter: '<span class="gl-text-black-normal gl-font-weight-bold">\1</span>')
end
def simple_search_highlight_and_truncate(text, phrase, options = {})
truncate_length = options.delete(:length) { 200 }
text = truncate(text, length: truncate_length)
......
......@@ -10,7 +10,4 @@
.gl-text-gray-500.gl-my-3
= sprintf(s_(' %{project_name}#%{issue_iid} &middot; opened %{issue_created} by %{author}'), { project_name: issue.project.full_name, issue_iid: issue.iid, issue_created: time_ago_with_tooltip(issue.created_at, placement: 'bottom'), author: link_to_member(@project, issue.author, avatar: false) }).html_safe
.description.term.col-sm-10.gl-px-0
- if search_service.use_elasticsearch? && @search_highlight[issue.id]&.description.present?
= Truncato.truncate(@search_highlight[issue.id].description.first, count_tags: false, count_tail: false, max_length: 200).html_safe
- elsif issue.description.present?
= simple_search_highlight_and_truncate(issue.description, @search_term, highlighter: '<span class="gl-text-black-normal gl-font-weight-bold">\1</span>')
= highlight_and_truncate_issue(issue, @search_term, @search_highlight)
......@@ -52,6 +52,14 @@ module EE
end
end
override :highlight_and_truncate_issue
def highlight_and_truncate_issue(issue, search_term, search_highlight)
return super unless search_service.use_elasticsearch? && search_highlight[issue.id]&.description.present?
# We use Elasticsearch highlighting for results from Elasticsearch
Truncato.truncate(search_highlight[issue.id].description.first, count_tags: false, count_tail: false, max_length: 200).html_safe
end
def revert_to_basic_search_filter_url
search_params = params
.permit(::SearchHelper::SEARCH_PERMITTED_PARAMS)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment