Fixes input to build_mongo_pages_query in /search route.
Moves database related functions from helpers to database module.