protected function postAddElement(Element_Interface $element) { $searchEntry = new Search_Backend_Data($element); $searchEntry->save(); }
// clear all data $db = Pimcore_Resource::get(); $db->query("TRUNCATE `search_backend_data`;"); $elementsPerLoop = 100; $types = array("asset", "document", "object"); foreach ($types as $type) { $listClassName = ucfirst($type) . "_List"; $list = new $listClassName(); $elementsTotal = $list->getTotalCount(); for ($i = 0; $i < ceil($elementsTotal / $elementsPerLoop); $i++) { $list->setLimit($elementsPerLoop); $list->setOffset($i * $elementsPerLoop); echo "Processing " . $type . ": " . ($list->getOffset() + $elementsPerLoop) . "/" . $elementsTotal . "\n"; $elements = $list->load(); foreach ($elements as $element) { try { $searchEntry = Search_Backend_Data::getForElement($element); if ($searchEntry instanceof Search_Backend_Data and $searchEntry->getId() instanceof Search_Backend_Data_Id) { $searchEntry->setDataFromElement($element); } else { $searchEntry = new Search_Backend_Data($element); } $searchEntry->save(); } catch (Exception $e) { Logger::err($e); } } Pimcore::collectGarbage(); } } $db->query("OPTIMIZE TABLE search_backend_data;");