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
f0040ded
Commit
f0040ded
authored
Sep 09, 2021
by
Zack Cuddy
Committed by
Etienne Baqué
Sep 09, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Global Search - Limited and Delimited Tab Counts
parent
bca6e454
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
53 additions
and
21 deletions
+53
-21
ee/lib/gitlab/elastic/search_results.rb
ee/lib/gitlab/elastic/search_results.rb
+20
-8
ee/lib/gitlab/elastic/snippet_search_results.rb
ee/lib/gitlab/elastic/snippet_search_results.rb
+1
-1
ee/spec/lib/gitlab/elastic/search_results_spec.rb
ee/spec/lib/gitlab/elastic/search_results_spec.rb
+12
-12
ee/spec/lib/gitlab/elastic/snippet_search_results_spec.rb
ee/spec/lib/gitlab/elastic/snippet_search_results_spec.rb
+20
-0
No files found.
ee/lib/gitlab/elastic/search_results.rb
View file @
f0040ded
...
...
@@ -3,8 +3,10 @@
module
Gitlab
module
Elastic
class
SearchResults
include
ActionView
::
Helpers
::
NumberHelper
include
Gitlab
::
Utils
::
StrongMemoize
ELASTIC_COUNT_LIMIT
=
10000
DEFAULT_PER_PAGE
=
Gitlab
::
SearchResults
::
DEFAULT_PER_PAGE
attr_reader
:current_user
,
:query
,
:public_and_internal_projects
,
:order_by
,
:sort
,
:filters
...
...
@@ -70,21 +72,21 @@ module Gitlab
def
formatted_count
(
scope
)
case
scope
when
'projects'
projects_count
.
to_s
elastic_search_limited_counter_with_delimiter
(
projects_count
)
when
'notes'
notes_count
.
to_s
elastic_search_limited_counter_with_delimiter
(
notes_count
)
when
'blobs'
blobs_count
.
to_s
elastic_search_limited_counter_with_delimiter
(
blobs_count
)
when
'wiki_blobs'
wiki_blobs_count
.
to_s
elastic_search_limited_counter_with_delimiter
(
wiki_blobs_count
)
when
'commits'
commits_count
.
to_s
elastic_search_limited_counter_with_delimiter
(
commits_count
)
when
'issues'
issues_count
.
to_s
elastic_search_limited_counter_with_delimiter
(
issues_count
)
when
'merge_requests'
merge_requests_count
.
to_s
elastic_search_limited_counter_with_delimiter
(
merge_requests_count
)
when
'milestones'
milestones_count
.
to_s
elastic_search_limited_counter_with_delimiter
(
milestones_count
)
end
end
...
...
@@ -339,6 +341,16 @@ module Gitlab
def
default_scope
'projects'
end
def
elastic_search_limited_counter_with_delimiter
(
count
)
if
count
.
nil?
number_with_delimiter
(
0
)
elsif
count
>=
ELASTIC_COUNT_LIMIT
number_with_delimiter
(
ELASTIC_COUNT_LIMIT
)
+
'+'
else
number_with_delimiter
(
count
)
end
end
end
end
end
ee/lib/gitlab/elastic/snippet_search_results.rb
View file @
f0040ded
...
...
@@ -9,7 +9,7 @@ module Gitlab
end
def
formatted_count
(
scope
)
snippet_titles_count
.
to_s
elastic_search_limited_counter_with_delimiter
(
snippet_titles_count
)
end
def
snippet_titles_count
...
...
ee/spec/lib/gitlab/elastic/search_results_spec.rb
View file @
f0040ded
...
...
@@ -43,21 +43,21 @@ RSpec.describe Gitlab::Elastic::SearchResults, :elastic, :clean_gitlab_redis_sha
let
(
:results
)
{
described_class
.
new
(
user
,
'hello world'
,
limit_project_ids
)
}
where
(
:scope
,
:count_method
,
:expected
)
do
'projects'
|
:projects_count
|
'1234
'
'notes'
|
:notes_count
|
'1234
'
'blobs'
|
:blobs_count
|
'1234
'
'wiki_blobs'
|
:wiki_blobs_count
|
'1234
'
'commits'
|
:commits_count
|
'1234
'
'issues'
|
:issues_count
|
'1234
'
'merge_requests'
|
:merge_requests_count
|
'1234
'
'milestones'
|
:milestones_count
|
'1234
'
'unknown'
|
nil
|
nil
where
(
:scope
,
:count_method
,
:
value
,
:
expected
)
do
'projects'
|
:projects_count
|
0
|
'0
'
'notes'
|
:notes_count
|
100
|
'100
'
'blobs'
|
:blobs_count
|
1000
|
'1,000
'
'wiki_blobs'
|
:wiki_blobs_count
|
1111
|
'1,111
'
'commits'
|
:commits_count
|
9999
|
'9,999
'
'issues'
|
:issues_count
|
10000
|
'10,000+
'
'merge_requests'
|
:merge_requests_count
|
20000
|
'10,000+
'
'milestones'
|
:milestones_count
|
nil
|
'0
'
'unknown'
|
nil
|
nil
|
nil
end
with_them
do
it
'returns the expected formatted count'
do
expect
(
results
).
to
receive
(
count_method
).
and_return
(
1234
)
if
count_method
it
'returns the expected formatted count
limited and delimited
'
do
expect
(
results
).
to
receive
(
count_method
).
and_return
(
value
)
if
count_method
expect
(
results
.
formatted_count
(
scope
)).
to
eq
(
expected
)
end
end
...
...
ee/spec/lib/gitlab/elastic/snippet_search_results_spec.rb
View file @
f0040ded
...
...
@@ -40,6 +40,26 @@ RSpec.describe Gitlab::Elastic::SnippetSearchResults, :elastic, :clean_gitlab_re
end
end
describe
'#formatted_count'
do
using
RSpec
::
Parameterized
::
TableSyntax
where
(
:value
,
:expected
)
do
1
|
'1'
9999
|
'9,999'
10000
|
'10,000+'
20000
|
'10,000+'
0
|
'0'
nil
|
'0'
end
with_them
do
it
'returns the expected formatted count limited and delimited'
do
expect
(
results
).
to
receive
(
:snippet_titles_count
).
and_return
(
value
)
expect
(
results
.
formatted_count
(
'snippets'
)).
to
eq
(
expected
)
end
end
end
describe
'#highlight_map'
do
it
'returns the expected highlight map'
do
expect
(
results
).
to
receive
(
:snippet_titles
).
and_return
([{
_source:
{
id:
1
},
highlight:
'test <span class="gl-text-gray-900 gl-font-weight-bold">highlight</span>'
}])
...
...
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