summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2016-09-12 09:32:32 +0000
committerRémy Coutable <remy@rymai.me>2016-09-12 09:32:32 +0000
commit45afdbef0de58f6de207b057e47151611d2ad7e6 (patch)
tree327bcec770a7dd96893ac00ec4b60a834ff602ae /lib
parent6c8516db241e20ecc678e394edbde1e618ad59ad (diff)
parent3a58dd2d8ffd0baf7a6a8f342d703cbdc34400bb (diff)
downloadgitlab-ce-45afdbef0de58f6de207b057e47151611d2ad7e6.tar.gz
Merge branch 'rc-api-use-search-globalservice-in-projects-search-api' into 'master'
API: Use Search::GlobalService in projects search API See merge request !6280
Diffstat (limited to 'lib')
-rw-r--r--lib/api/projects.rb15
1 files changed, 3 insertions, 12 deletions
diff --git a/lib/api/projects.rb b/lib/api/projects.rb
index 4033f597859..644d836ed0b 100644
--- a/lib/api/projects.rb
+++ b/lib/api/projects.rb
@@ -428,18 +428,9 @@ module API
# Example Request:
# GET /projects/search/:query
get "/search/:query" do
- ids = current_user.authorized_projects.map(&:id)
- visibility_levels = [ Gitlab::VisibilityLevel::INTERNAL, Gitlab::VisibilityLevel::PUBLIC ]
- projects = Project.where("(id in (?) OR visibility_level in (?)) AND (name LIKE (?))", ids, visibility_levels, "%#{params[:query]}%")
- sort = params[:sort] == 'desc' ? 'desc' : 'asc'
-
- projects = case params["order_by"]
- when 'id' then projects.order("id #{sort}")
- when 'name' then projects.order("name #{sort}")
- when 'created_at' then projects.order("created_at #{sort}")
- when 'last_activity_at' then projects.order("last_activity_at #{sort}")
- else projects
- end
+ search_service = Search::GlobalService.new(current_user, search: params[:query]).execute
+ projects = search_service.objects('projects', params[:page])
+ projects = projects.reorder(project_order_by => project_sort)
present paginate(projects), with: Entities::Project
end