Refactoring of search queries