Backend\Core\Installer\ModuleInstaller::addSearchIndex PHP Method

addSearchIndex() protected method

Add a search index
protected addSearchIndex ( string $module, integer $otherId, array $fields, string $language )
$module string The module wherein will be searched.
$otherId integer The id of the record.
$fields array A key/value pair of fields to index.
$language string The frontend language for this entry.
    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());
        }
    }