public static function instance($itemid, $componentname, $areaname, $engine = false) {

        if ($engine === false) {
            $search = \core_search\manager::instance();
            $engine = $search->get_engine();
        }

        $pluginname = $engine->get_plugin_name();

        if (!empty(self::$docclassnames[$pluginname])) {
            return new self::$docclassnames[$pluginname]($itemid, $componentname, $areaname);
        }

        self::$docclassnames[$pluginname] = $engine->get_document_classname();

        return new self::$docclassnames[$pluginname]($itemid, $componentname, $areaname);
    }