Rewrite advanced search for better performance