Postgres::createFtsDictionary PHP Method

createFtsDictionary() public method

Creates a new FTS dictionary or FTS dictionary template.
public createFtsDictionary ( string $dictname, boolean $isTemplate = false, string $template = '', string $lexize = '', string $init = '', string $option = '', string $comment = '' )
$dictname string The name of the FTS dictionary to create
$isTemplate boolean Flag whether we create usual dictionary or dictionary template
$template string The existing FTS dictionary to be used as template for the new one
$lexize string The name of the function, which does transformation of input word
$init string The name of the function, which initializes dictionary
$option string Usually, it stores various options required for the dictionary
$comment string If omitted, defaults to nothing
    function createFtsDictionary($dictname, $isTemplate = false, $template = '', $lexize = '', $init = '', $option = '', $comment = '')
    {
        $f_schema = $this->_schema;
        $this->fieldClean($f_schema);
        $this->fieldClean($dictname);
        $this->fieldClean($template);
        $this->fieldClean($lexize);
        $this->fieldClean($init);
        $this->fieldClean($option);
        $sql = "CREATE TEXT SEARCH";
        if ($isTemplate) {
            $sql .= " TEMPLATE \"{$f_schema}\".\"{$dictname}\" (";
            if ($lexize != '') {
                $sql .= " LEXIZE = {$lexize}";
            }
            if ($init != '') {
                $sql .= ", INIT = {$init}";
            }
            $sql .= ")";
            $whatToComment = 'TEXT SEARCH TEMPLATE';
        } else {
            $sql .= " DICTIONARY \"{$f_schema}\".\"{$dictname}\" (";
            if ($template != '') {
                $this->fieldClean($template['schema']);
                $this->fieldClean($template['name']);
                $template = "\"{$template['schema']}\".\"{$template['name']}\"";
                $sql .= " TEMPLATE = {$template}";
            }
            if ($option != '') {
                $sql .= ", {$option}";
            }
            $sql .= ")";
            $whatToComment = 'TEXT SEARCH DICTIONARY';
        }
        /* if comment, begin a transaction to
         * run both commands */
        if ($comment != '') {
            $status = $this->beginTransaction();
            if ($status != 0) {
                return -1;
            }
        }
        // Create the FTS dictionary
        $status = $this->execute($sql);
        if ($status != 0) {
            $this->rollbackTransaction();
            return -1;
        }
        // Set the comment
        if ($comment != '') {
            $status = $this->setComment($whatToComment, $dictname, '', $comment);
            if ($status != 0) {
                $this->rollbackTransaction();
                return -1;
            }
        }
        return $this->endTransaction();
    }
Postgres