alphagov/rummager — pull request #271 by rboulton (2014-07-17 09:41:17+00:00)
Title: Add control over ordering of facet values

Returned facet values can be ordered by setting the "order" option in a
facet parameter. The available orderings are:

- count: order by the number of documents in the search matching the
facet value.
- slug: the slug in the facet value
- link: the link in the facet value
- title: the title in the facet value
- filtered: whether the value is used in an active filter

Each ordering may be preceded by a "-" to sort in descending order.
Multiple orderings can be specified, in priority order, separated by a
colon. The default ordering is "filtered:-count:slug".

Previously, the hard-coded ordering was equivalent to "filtered:-count",
with items with an equal count being returned in whatever order
elasticsearch returned the values (which is, I believe, dependent on
insertion order of documents in the elasticsearch database). Some tests
needed updating to reflect the final sort by slug instead of
elasticsearch order.

This also changes the return format of all facets to the "expanded"
form. ie: instead of returning a string for the value, return a hash,
containing at the minimum a "slug" key. This was already the return
format for the organisations and specialist_sections facets, which are
the only ones in use, and it's better (and less code) to be consistent.
This change did result in an unfortunately large amount of test churn,
sadly.