Commit 8785cfb8 authored by Stan Hu's avatar Stan Hu

Merge branch '254840-fix-ce-regression-issue-highlight' into 'master'

[RUN AS-IF-FOSS] Fix regression in FOSS for search issue description highlight

Closes #254840

See merge request gitlab-org/gitlab!43068
parents 760eb154 bc3603b8
...@@ -294,6 +294,11 @@ module SearchHelper ...@@ -294,6 +294,11 @@ module SearchHelper
sanitize(html, tags: %w(a p ol ul li pre code)) sanitize(html, tags: %w(a p ol ul li pre code))
end 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 = {}) def simple_search_highlight_and_truncate(text, phrase, options = {})
truncate_length = options.delete(:length) { 200 } truncate_length = options.delete(:length) { 200 }
text = truncate(text, length: truncate_length) text = truncate(text, length: truncate_length)
......
...@@ -10,7 +10,4 @@ ...@@ -10,7 +10,4 @@
.gl-text-gray-500.gl-my-3 .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 = 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 .description.term.col-sm-10.gl-px-0
- if search_service.use_elasticsearch? && @search_highlight[issue.id]&.description.present? = highlight_and_truncate_issue(issue, @search_term, @search_highlight)
= 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>')
...@@ -52,6 +52,14 @@ module EE ...@@ -52,6 +52,14 @@ module EE
end end
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 def revert_to_basic_search_filter_url
search_params = params search_params = params
.permit(::SearchHelper::SEARCH_PERMITTED_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