optimize TwigExtension::search()