refactor search query