Refactoring search query