Commit 296f70a0 authored by Dylan Griffith's avatar Dylan Griffith

Extract constants HIGHLIGHT_START_TAG HIGHLIGHT_END_TAG

parent f24f5fb5
......@@ -4,6 +4,8 @@ module Elastic
module Latest
module GitClassProxy
SHA_REGEX = /\A[0-9a-f]{5,40}\z/i.freeze
HIGHLIGHT_START_TAG = 'gitlabelasticsearch→'
HIGHLIGHT_END_TAG = '←gitlabelasticsearch'
def elastic_search(query, type: 'all', page: 1, per: 20, options: {})
results = { blobs: [], commits: [] }
......@@ -95,8 +97,8 @@ module Elastic
end
query_hash[:highlight] = {
pre_tags: ["gitlabelasticsearch→"],
post_tags: ["←gitlabelasticsearch"],
pre_tags: [HIGHLIGHT_START_TAG],
post_tags: [HIGHLIGHT_END_TAG],
fields: es_fields
}
end
......@@ -157,8 +159,8 @@ module Elastic
if options[:highlight]
query_hash[:highlight] = {
pre_tags: ["gitlabelasticsearch→"],
post_tags: ["←gitlabelasticsearch"],
pre_tags: [HIGHLIGHT_START_TAG],
post_tags: [HIGHLIGHT_END_TAG],
number_of_fragments: 0, # highlighted text fragments do not work well for code as we want to show a few whole lines of code. We need to get the whole content to determine the exact line number that was highlighted.
fields: {
"blob.content" => {},
......
......@@ -128,7 +128,7 @@ module Gitlab
found_line_number = 0
highlight_content.each_line.each_with_index do |line, index|
if line.include?('gitlabelasticsearch→')
if line.include?(::Elastic::Latest::GitClassProxy::HIGHLIGHT_START_TAG)
found_line_number = index
break
end
......
......@@ -84,7 +84,7 @@ RSpec.describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need
result = {
'_source' => blob,
'highlight' => {
'blob.content' => ["foo\ngitlabelasticsearch→bar←gitlabelasticsearch\nbaz\n"]
'blob.content' => ["foo\n#{::Elastic::Latest::GitClassProxy::HIGHLIGHT_START_TAG}bar#{::Elastic::Latest::GitClassProxy::HIGHLIGHT_END_TAG}\nbaz\n"]
}
}
......@@ -120,7 +120,7 @@ RSpec.describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need
bar
bar
foo
gitlabelasticsearch→bar←gitlabelasticsearch # this is the highlighted bar
#{::Elastic::Latest::GitClassProxy::HIGHLIGHT_START_TAG}bar#{::Elastic::Latest::GitClassProxy::HIGHLIGHT_END_TAG} # this is the highlighted bar
baz
boo
bar
......
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