Code refactoring for complex searches