Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
296f70a0
Commit
296f70a0
authored
Sep 25, 2020
by
Dylan Griffith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract constants HIGHLIGHT_START_TAG HIGHLIGHT_END_TAG
parent
f24f5fb5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
7 deletions
+9
-7
ee/lib/elastic/latest/git_class_proxy.rb
ee/lib/elastic/latest/git_class_proxy.rb
+6
-4
ee/lib/gitlab/elastic/search_results.rb
ee/lib/gitlab/elastic/search_results.rb
+1
-1
ee/spec/lib/gitlab/elastic/search_results_spec.rb
ee/spec/lib/gitlab/elastic/search_results_spec.rb
+2
-2
No files found.
ee/lib/elastic/latest/git_class_proxy.rb
View file @
296f70a0
...
...
@@ -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"
=>
{},
...
...
ee/lib/gitlab/elastic/search_results.rb
View file @
296f70a0
...
...
@@ -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
...
...
ee/spec/lib/gitlab/elastic/search_results_spec.rb
View file @
296f70a0
...
...
@@ -84,7 +84,7 @@ RSpec.describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need
result
=
{
'_source'
=>
blob
,
'highlight'
=>
{
'blob.content'
=>
[
"foo
\n
gitlabelasticsearch→bar←gitlabelasticsearch
\n
baz
\n
"
]
'blob.content'
=>
[
"foo
\n
#{
::
Elastic
::
Latest
::
GitClassProxy
::
HIGHLIGHT_START_TAG
}
bar
#{
::
Elastic
::
Latest
::
GitClassProxy
::
HIGHLIGHT_END_TAG
}
\n
baz
\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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment