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
40e6800d
Commit
40e6800d
authored
Dec 23, 2016
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix ES search for non-default branches
parent
cdb51842
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
65 additions
and
28 deletions
+65
-28
app/views/search/results/_blob.html.haml
app/views/search/results/_blob.html.haml
+1
-1
lib/gitlab/elastic/project_search_results.rb
lib/gitlab/elastic/project_search_results.rb
+6
-4
lib/gitlab/file_finder.rb
lib/gitlab/file_finder.rb
+32
-0
lib/gitlab/project_search_results.rb
lib/gitlab/project_search_results.rb
+1
-17
spec/lib/gitlab/elastic/project_search_results_spec.rb
spec/lib/gitlab/elastic/project_search_results_spec.rb
+25
-6
No files found.
app/views/search/results/_blob.html.haml
View file @
40e6800d
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
-
blob
=
parse_search_result
(
blob
)
-
blob
=
parse_search_result
(
blob
)
-
file_name
=
blob
.
filename
-
file_name
=
blob
.
filename
-
ref
=
blob
.
ref
-
ref
=
@search_results
.
repository_
ref
-
blob_link
=
namespace_project_blob_path
(
project
.
namespace
,
project
,
tree_join
(
ref
,
file_name
))
-
blob_link
=
namespace_project_blob_path
(
project
.
namespace
,
project
,
tree_join
(
ref
,
file_name
))
.blob-result
.blob-result
.file-holder
.file-holder
...
...
lib/gitlab/elastic/project_search_results.rb
View file @
40e6800d
...
@@ -65,7 +65,7 @@ module Gitlab
...
@@ -65,7 +65,7 @@ module Gitlab
)[
:blobs
][
:results
].
response
)[
:blobs
][
:results
].
response
else
else
Kaminari
.
paginate_array
(
Kaminari
.
paginate_array
(
project
.
repository
.
search_files
(
query
,
repository_ref
)
Gitlab
::
FileFinder
.
new
(
project
,
repository_ref
).
find
(
query
)
)
)
end
end
end
end
...
@@ -105,10 +105,12 @@ module Gitlab
...
@@ -105,10 +105,12 @@ module Gitlab
per_page:
per_page
per_page:
per_page
)
)
else
else
offset
=
per_page
*
((
page
||
1
)
-
1
)
Kaminari
.
paginate_array
(
Kaminari
.
paginate_array
(
project
.
repository
.
find_commits_by_message
(
query
)
.
compact
,
project
.
repository
.
find_commits_by_message
(
query
),
page:
(
page
||
1
).
to_i
,
offset:
offset
,
per_page
:
per_page
limit
:
per_page
)
)
end
end
end
end
...
...
lib/gitlab/file_finder.rb
0 → 100644
View file @
40e6800d
# This class finds files in a repository by name and content
# the result is joined and sorted by file name
module
Gitlab
class
FileFinder
BATCH_SIZE
=
100
attr_reader
:project
,
:ref
def
initialize
(
project
,
ref
)
@project
=
project
@ref
=
ref
end
def
find
(
query
)
blobs
=
project
.
repository
.
search_files_by_content
(
query
,
ref
).
first
(
BATCH_SIZE
)
found_file_names
=
Set
.
new
results
=
blobs
.
map
do
|
blob
|
blob
=
Gitlab
::
ProjectSearchResults
.
parse_search_result
(
blob
)
found_file_names
<<
blob
.
filename
[
blob
.
filename
,
blob
]
end
project
.
repository
.
search_files_by_name
(
query
,
ref
).
first
(
BATCH_SIZE
).
each
do
|
filename
|
results
<<
[
filename
,
nil
]
unless
found_file_names
.
include?
(
filename
)
end
results
.
sort_by
(
&
:first
)
end
end
end
lib/gitlab/project_search_results.rb
View file @
40e6800d
...
@@ -74,23 +74,7 @@ module Gitlab
...
@@ -74,23 +74,7 @@ module Gitlab
private
private
def
blobs
def
blobs
@blobs
||=
begin
@blobs
||=
Gitlab
::
FileFinder
.
new
(
project
,
repository_ref
).
find
(
query
)
blobs
=
project
.
repository
.
search_files_by_content
(
query
,
repository_ref
).
first
(
100
)
found_file_names
=
Set
.
new
results
=
blobs
.
map
do
|
blob
|
blob
=
self
.
class
.
parse_search_result
(
blob
)
found_file_names
<<
blob
.
filename
[
blob
.
filename
,
blob
]
end
project
.
repository
.
search_files_by_name
(
query
,
repository_ref
).
first
(
100
).
each
do
|
filename
|
results
<<
[
filename
,
nil
]
unless
found_file_names
.
include?
(
filename
)
end
results
.
sort_by
(
&
:first
)
end
end
end
def
wiki_blobs
def
wiki_blobs
...
...
spec/lib/gitlab/elastic/project_search_results_spec.rb
View file @
40e6800d
...
@@ -46,30 +46,49 @@ describe Gitlab::Elastic::ProjectSearchResults, lib: true do
...
@@ -46,30 +46,49 @@ describe Gitlab::Elastic::ProjectSearchResults, lib: true do
create
:note
,
note:
'bla-bla term'
,
project:
project1
create
:note
,
note:
'bla-bla term'
,
project:
project1
# Wiki
# Wiki
project
.
wiki
.
create_page
(
"index_page"
,
"term"
)
project
.
wiki
.
create_page
(
'index_page'
,
'term'
)
project
.
wiki
.
index_blobs
project
.
wiki
.
index_blobs
project1
.
wiki
.
create_page
(
"index_page"
,
" term"
)
project1
.
wiki
.
create_page
(
'index_page'
,
' term'
)
project1
.
wiki
.
index_blobs
project1
.
wiki
.
index_blobs
Gitlab
::
Elastic
::
Helper
.
refresh_index
Gitlab
::
Elastic
::
Helper
.
refresh_index
result
=
Gitlab
::
Elastic
::
ProjectSearchResults
.
new
(
user
,
"term"
,
project
.
id
)
result
=
Gitlab
::
Elastic
::
ProjectSearchResults
.
new
(
user
,
'term'
,
project
.
id
)
expect
(
result
.
notes_count
).
to
eq
(
1
)
expect
(
result
.
notes_count
).
to
eq
(
1
)
expect
(
result
.
wiki_blobs_count
).
to
eq
(
1
)
expect
(
result
.
wiki_blobs_count
).
to
eq
(
1
)
expect
(
result
.
blobs_count
).
to
eq
(
1
)
expect
(
result
.
blobs_count
).
to
eq
(
1
)
result1
=
Gitlab
::
Elastic
::
ProjectSearchResults
.
new
(
user
,
"initial"
,
project
.
id
)
result1
=
Gitlab
::
Elastic
::
ProjectSearchResults
.
new
(
user
,
'initial'
,
project
.
id
)
expect
(
result1
.
commits_count
).
to
eq
(
1
)
expect
(
result1
.
commits_count
).
to
eq
(
1
)
end
end
end
end
describe
"search for commits in non-default branch"
do
describe
"search for commits in non-default branch"
do
it
"finds needed commit"
do
it
'finds needed commit'
do
project
=
create
:project
project
=
create
:project
result
=
Gitlab
::
Elastic
::
ProjectSearchResults
.
new
(
user
,
"initial"
,
project
.
id
,
'test'
)
result
=
Gitlab
::
Elastic
::
ProjectSearchResults
.
new
(
user
,
'initial'
,
project
.
id
,
'test'
)
expect
(
result
.
commits_count
).
to
eq
(
1
)
expect
(
result
.
commits_count
).
to
eq
(
1
)
end
end
it
'responds to total_pages method'
do
project
=
create
:project
result
=
Gitlab
::
Elastic
::
ProjectSearchResults
.
new
(
user
,
'initial'
,
project
.
id
,
'test'
)
expect
(
result
.
objects
(
'commits'
).
total_pages
).
to
eq
(
1
)
end
end
describe
'search for blobs in non-default branch'
do
it
'users FileFinder instead of ES search'
do
project
=
create
:project
expect_any_instance_of
(
Gitlab
::
FileFinder
).
to
receive
(
:find
).
with
(
'initial'
).
and_return
([])
result
=
Gitlab
::
Elastic
::
ProjectSearchResults
.
new
(
user
,
'initial'
,
project
.
id
,
'test'
)
result
.
blobs_count
end
end
end
describe
'confidential issues'
do
describe
'confidential issues'
do
...
...
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