Commit 3a58dd2d authored by Rémy Coutable's avatar Rémy Coutable

Use Search::GlobalService.new in the `GET /projects/search/:query` endpoint

Also streamline the sorting part while we're at it.

That being done, there's currently a duplication between
`GET /projects/search/:query` and `GET /projects?search=:search`
so we might want to keep only the latter for 9.0...
Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 874ad681
...@@ -14,6 +14,7 @@ v 8.12.0 (unreleased) ...@@ -14,6 +14,7 @@ v 8.12.0 (unreleased)
- Add font color contrast to external label in admin area (ClemMakesApps) - Add font color contrast to external label in admin area (ClemMakesApps)
- Change logo animation to CSS (ClemMakesApps) - Change logo animation to CSS (ClemMakesApps)
- Instructions for enabling Git packfile bitmaps !6104 - Instructions for enabling Git packfile bitmaps !6104
- Use Search::GlobalService.new in the `GET /projects/search/:query` endpoint
- Fix pagination on user snippets page - Fix pagination on user snippets page
- Escape search term before passing it to Regexp.new !6241 (winniehell) - Escape search term before passing it to Regexp.new !6241 (winniehell)
- Fix pinned sidebar behavior in smaller viewports !6169 - Fix pinned sidebar behavior in smaller viewports !6169
...@@ -111,7 +112,6 @@ v 8.12.0 (unreleased) ...@@ -111,7 +112,6 @@ v 8.12.0 (unreleased)
- Use default clone protocol on "check out, review, and merge locally" help page URL - Use default clone protocol on "check out, review, and merge locally" help page URL
- API for Ci Lint !5953 (Katarzyna Kobierska Urszula Budziszewska) - API for Ci Lint !5953 (Katarzyna Kobierska Urszula Budziszewska)
- Allow bulk update merge requests from merge requests index page - Allow bulk update merge requests from merge requests index page
- Project search API is now agnostic to casing
v 8.11.6 (unreleased) v 8.11.6 (unreleased)
......
...@@ -428,18 +428,9 @@ module API ...@@ -428,18 +428,9 @@ module API
# Example Request: # Example Request:
# GET /projects/search/:query # GET /projects/search/:query
get "/search/:query" do get "/search/:query" do
ids = current_user.authorized_projects.map(&:id) search_service = Search::GlobalService.new(current_user, search: params[:query]).execute
visibility_levels = [ Gitlab::VisibilityLevel::INTERNAL, Gitlab::VisibilityLevel::PUBLIC ] projects = search_service.objects('projects', params[:page])
projects = Project.where("(id in (?) OR visibility_level in (?)) AND (LOWER(name) LIKE LOWER((?)))", ids, visibility_levels, "%#{params[:query]}%") projects = projects.reorder(project_order_by => project_sort)
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
present paginate(projects), with: Entities::Project present paginate(projects), with: Entities::Project
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment