Skip to content

Add sorting to search APIs

Dylan Griffith requested to merge 251211-add-sorting-to-search-api into master

What does this MR do?

This adds 2 params to the search APIs order_by (supports only created_at) and sort (supports asc or desc).

Sorting already exists for search results from the web. Most of this code for searching is shared. Unfortunately in the web search results we had to implement this by using a single parameter. In order for our API to be in line with other APIs it seemed preferable to implement sorting as 2 params (field, direction).

To make matters worse the web sorting does things like created_asc for sorting by created_at asc. So it wasn't even perfectly constructed by concatenating field name and direction. Unfortunately the simplest option here seemed to be to push the understanding of how to interpret these different params into the searching code so it needs to handle 2 different meanings for the sort param.

I considered changing the web code to do a translation of params before passing down to the SearchService but this was tricky due params being passed in and also @sort is used by the view. We may in future be able to refactor this to use 2 params but it seemed tricky to introduce now with a single form field.

Screenshots (strongly suggested)

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team

Related to #251211 (closed)

Edited by Dylan Griffith

Merge request reports

Loading