Search resources by keyword ID, and some refactorings

This adds an option to search resources by keyword ID (e.g. GET /keyword/44141956).

Introducing yet another option started to make the code messy, so this pull request also contains some refactorings to improve the overall structure of the controller and model classes (see individual commits for details).