Refactor search in controller