• Dylan Griffith's avatar
    Always sort Elasticsearch searches by relevance not updated_at · e2685352
    Dylan Griffith authored
    **TL;DR** Elasticsearch defaults to sorting by `_score` and this is what
    we want so remove all the explicit sorting.
    
    At present some searches are being sorted by `_score` (ie. the relevance
    score) while others are being first sorted by `updated_at` then
    `_score`.
    
    There doesn't really appear to be any good reason to use `updated_at` as
    the primary sort followed by `_score` since this will bury the most
    relevant matches behind lots of recent matches. Using sort in this way
    will only ever sort by `_score` if the `updated_at` was equal but this
    is basically never going to happen since these are timestamps so
    `_score` in practice is never factoring in to the sorting which probably
    was never the intent here.
    
    Since the [default sorting is by
    score](https://www.elastic.co/guide/en/elasticsearch/guide/master/sorting.html)
    we can leave it out of all queries.
    
    We can in future look into whether or not we want recency to factor into
    the sorting using more advanced tools like
    [`function_score`](https://www.elastic.co/guide/en/elasticsearch/guide/current/function-score-query.html)
    but for now sorting just by relevance is better than sorting just by
    `updated_at`.
    e2685352
snippet_search_results_spec.rb 2.73 KB