diff options
author | Jarka Kadlecová <jarka@gitlab.com> | 2018-01-31 17:59:59 +0300 |
---|---|---|
committer | Jarka Kadlecová <jarka@gitlab.com> | 2018-02-06 18:02:02 +0300 |
commit | 7381944565701f2a8db5d58d5bc3c7e52e7f60bf (patch) | |
tree | a9bb7687b3809082555bd78dd5e1c5696d768910 /lib/gitlab | |
parent | 0e15a5b805e832c22c67cead8c4829e6c77cd498 (diff) |
Support search in API
Diffstat (limited to 'lib/gitlab')
-rw-r--r-- | lib/gitlab/project_search_results.rb | 7 | ||||
-rw-r--r-- | lib/gitlab/search_results.rb | 10 | ||||
-rw-r--r-- | lib/gitlab/snippet_search_results.rb | 4 |
3 files changed, 10 insertions, 11 deletions
diff --git a/lib/gitlab/project_search_results.rb b/lib/gitlab/project_search_results.rb index 4823f703ba4..0846fdc4de3 100644 --- a/lib/gitlab/project_search_results.rb +++ b/lib/gitlab/project_search_results.rb @@ -2,14 +2,15 @@ module Gitlab class ProjectSearchResults < SearchResults attr_reader :project, :repository_ref - def initialize(current_user, project, query, repository_ref = nil) + def initialize(current_user, project, query, repository_ref = nil, per_page: 20) @current_user = current_user @project = project @repository_ref = repository_ref.presence || project.default_branch @query = query + @per_page = per_page end - def objects(scope, page = nil) + def objects(scope, page = nil, without_counts = true) case scope when 'notes' notes.page(page).per(per_page) @@ -20,7 +21,7 @@ module Gitlab when 'commits' Kaminari.paginate_array(commits).page(page).per(per_page) else - super(scope, page, false) + super(scope, page, without_counts) end end diff --git a/lib/gitlab/search_results.rb b/lib/gitlab/search_results.rb index 7362514167f..5ad219179f3 100644 --- a/lib/gitlab/search_results.rb +++ b/lib/gitlab/search_results.rb @@ -10,6 +10,7 @@ module Gitlab @ref = opts.fetch(:ref, nil) @startline = opts.fetch(:startline, nil) @data = opts.fetch(:data, nil) + @per_page = opts.fetch(:per_page, 20) end def path @@ -21,7 +22,7 @@ module Gitlab end end - attr_reader :current_user, :query + attr_reader :current_user, :query, :per_page # Limit search results by passed projects # It allows us to search only for projects user has access to @@ -33,11 +34,12 @@ module Gitlab # query attr_reader :default_project_filter - def initialize(current_user, limit_projects, query, default_project_filter: false) + def initialize(current_user, limit_projects, query, default_project_filter: false, per_page: 20) @current_user = current_user @limit_projects = limit_projects || Project.all @query = query @default_project_filter = default_project_filter + @per_page = per_page end def objects(scope, page = nil, without_count = true) @@ -153,10 +155,6 @@ module Gitlab 'projects' end - def per_page - 20 - end - def project_ids_relation limit_projects.select(:id).reorder(nil) end diff --git a/lib/gitlab/snippet_search_results.rb b/lib/gitlab/snippet_search_results.rb index 4f86b3e8f73..98c43475303 100644 --- a/lib/gitlab/snippet_search_results.rb +++ b/lib/gitlab/snippet_search_results.rb @@ -9,14 +9,14 @@ module Gitlab @query = query end - def objects(scope, page = nil) + def objects(scope, page = nil, without_counts = true) case scope when 'snippet_titles' snippet_titles.page(page).per(per_page) when 'snippet_blobs' snippet_blobs.page(page).per(per_page) else - super(scope, nil, false) + super(scope, nil, without_counts) end end |