Add ability to specify different collection methods

From Pivotal [#52056357], "Add functionality to backdrop to sum items"

This change adds an option to the collect parameter, so that you can ask for `?collect=field:sum` (and a few other methods).

(Rob says: we've got some query code in `database.py` that shouldn't be there. Can be refactored later.)