Search scoped by organisation

* Added the ability to scope searches to documents related to an organisation
* Refactored the escaping code
* Refactored the code for generating search queries