moved some search logic out of routes and into model