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
7540e120
Commit
7540e120
authored
Nov 17, 2016
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix Elasticsearch
parent
acb8e33d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
51 deletions
+53
-51
app/helpers/search_helper.rb
app/helpers/search_helper.rb
+2
-49
app/views/search/results/_blob.html.haml
app/views/search/results/_blob.html.haml
+8
-2
lib/gitlab/elastic/search_results.rb
lib/gitlab/elastic/search_results.rb
+43
-0
No files found.
app/helpers/search_helper.rb
View file @
7540e120
...
...
@@ -32,59 +32,12 @@ module SearchHelper
def
parse_search_result
(
result
)
if
result
.
is_a?
(
String
)
parse_search_result_from_grep
(
result
)
Gitlab
::
ProjectSearchResults
.
parse_search_result
(
result
)
else
parse_search_result_from_elastic
(
result
)
Gitlab
::
Elastic
::
SearchResults
.
parse_search_result
(
result
)
end
end
def
parse_search_result_from_elastic
(
result
)
ref
=
result
[
"_source"
][
"blob"
][
"commit_sha"
]
filename
=
result
[
"_source"
][
"blob"
][
"path"
]
extname
=
File
.
extname
(
filename
)
basename
=
filename
.
sub
(
/
#{
extname
}
$/
,
''
)
content
=
result
[
"_source"
][
"blob"
][
"content"
]
total_lines
=
content
.
lines
.
size
highlighted_content
=
result
[
"highlight"
][
"blob.content"
]
term
=
highlighted_content
&&
highlighted_content
[
0
].
match
(
/gitlabelasticsearch→(.*?)←gitlabelasticsearch/
)[
1
]
found_line_number
=
0
content
.
each_line
.
each_with_index
do
|
line
,
index
|
if
term
&&
line
.
include?
(
term
)
found_line_number
=
index
break
end
end
from
=
if
found_line_number
>=
2
found_line_number
-
2
else
found_line_number
end
to
=
if
(
total_lines
-
found_line_number
)
>
3
found_line_number
+
2
else
found_line_number
end
data
=
content
.
lines
[
from
..
to
]
OpenStruct
.
new
(
filename:
filename
,
basename:
basename
,
ref:
ref
,
startline:
from
+
1
,
data:
data
.
join
)
end
def
parse_search_result_from_grep
(
result
)
Gitlab
::
ProjectSearchResults
.
parse_search_result
(
result
)
end
def
find_project_for_blob
(
blob
)
Project
.
find
(
blob
[
'_parent'
])
end
...
...
app/views/search/results/_blob.html.haml
View file @
7540e120
-
file_name
,
blob
=
blob
-
project
=
@project
||
find_project_for_blob
(
blob
)
-
ref
=
@search_results
.
repository_ref
-
if
blob
.
is_a?
(
Array
)
-
file_name
,
blob
=
blob
-
else
-
blob
=
parse_search_result
(
blob
)
-
file_name
=
blob
.
filename
-
ref
=
blob
.
ref
-
blob_link
=
namespace_project_blob_path
(
project
.
namespace
,
project
,
tree_join
(
ref
,
file_name
))
.blob-result
.file-holder
...
...
lib/gitlab/elastic/search_results.rb
View file @
7540e120
...
...
@@ -57,6 +57,49 @@ module Gitlab
@milestones_count
||=
milestones
.
total_count
end
def
self
.
parse_search_result
(
result
)
ref
=
result
[
"_source"
][
"blob"
][
"commit_sha"
]
filename
=
result
[
"_source"
][
"blob"
][
"path"
]
extname
=
File
.
extname
(
filename
)
basename
=
filename
.
sub
(
/
#{
extname
}
$/
,
''
)
content
=
result
[
"_source"
][
"blob"
][
"content"
]
total_lines
=
content
.
lines
.
size
highlighted_content
=
result
[
"highlight"
][
"blob.content"
]
term
=
highlighted_content
&&
highlighted_content
[
0
].
match
(
/gitlabelasticsearch→(.*?)←gitlabelasticsearch/
)[
1
]
found_line_number
=
0
content
.
each_line
.
each_with_index
do
|
line
,
index
|
if
term
&&
line
.
include?
(
term
)
found_line_number
=
index
break
end
end
from
=
if
found_line_number
>=
2
found_line_number
-
2
else
found_line_number
end
to
=
if
(
total_lines
-
found_line_number
)
>
3
found_line_number
+
2
else
found_line_number
end
data
=
content
.
lines
[
from
..
to
]
OpenStruct
.
new
(
filename:
filename
,
basename:
basename
,
ref:
ref
,
startline:
from
+
1
,
data:
data
.
join
)
end
private
def
base_options
...
...
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