• Dylan Griffith's avatar
    Add ability to sort to search API · 1ecfca53
    Dylan Griffith authored
    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.
    1ecfca53
search.rb 4.73 KB