refactor search controller and view code