protected function addSearchIndex($module, $otherId, array $fields, $language)
{
// get db
$db = $this->getDB();
// validate cache
if (empty(self::$modules)) {
// get all modules
self::$modules = (array) $db->getColumn('SELECT m.name FROM modules AS m');
}
// module exists?
if (!in_array('Search', self::$modules)) {
return;
}
// no fields?
if (empty($fields)) {
return;
}
// insert search index
foreach ($fields as $field => $value) {
// reformat value
$value = strip_tags((string) $value);
// insert in db
$db->execute('INSERT INTO search_index (module, other_id, language, field, value, active)
VALUES (?, ?, ?, ?, ?, ?)
ON DUPLICATE KEY UPDATE value = ?, active = ?', array((string) $module, (int) $otherId, (string) $language, (string) $field, $value, 'Y', $value, 'Y'));
}
// invalidate the cache for search
$finder = new Finder();
$filesystem = new Filesystem();
foreach ($finder->files()->in(FRONTEND_CACHE_PATH . '/Search/') as $file) {
/** @var $file \SplFileInfo */
$filesystem->remove($file->getRealPath());
}
}