Move the search function from Main to the directive controller