diff options
author | Rémy Coutable <remy@rymai.me> | 2016-09-12 09:32:32 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-09-12 09:32:32 +0000 |
commit | 45afdbef0de58f6de207b057e47151611d2ad7e6 (patch) | |
tree | 327bcec770a7dd96893ac00ec4b60a834ff602ae /lib | |
parent | 6c8516db241e20ecc678e394edbde1e618ad59ad (diff) | |
parent | 3a58dd2d8ffd0baf7a6a8f342d703cbdc34400bb (diff) | |
download | gitlab-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.rb | 15 |
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 |