refactor search query formatting