Make search pagination metadata consistent with listings

Refactors the code from the previous commit so it can be used by both
the listing pages as well as the search results.

I've added a currentUrl middleware which makes it easier generate links
to previous/next pages.