Пример #1
0
 /**
  * Optimize a RT index.
  * @param string $indexName
  */
 public function optimizeRTIndex($indexName)
 {
     if (!is_null($this->sphinxQL)) {
         $this->sphinxQL->queryExec(sprintf('FLUSH RTINDEX %s', $indexName));
         $this->sphinxQL->queryExec(sprintf('OPTIMIZE INDEX %s', $indexName));
     }
 }
Пример #2
0
 public function __construct(array $options = [])
 {
     parent::__construct($options);
     $result = parent::exec("describe site", true);
     $this->table = $result === false ? 'settings' : 'site';
     $this->setCovers();
     return $this->pdo;
 }
Пример #3
0
function BackupDatabase()
{
    $db = new DB();
    $c = new ColorCLI();
    $DIR = dirname(__FILE__);
    if (Utility::hasCommand("php5")) {
        $PHP = "php5";
    } else {
        $PHP = "php";
    }
    //Backup based on database system
    if ($db->dbSystem() == "mysql") {
        system("{$PHP} {$DIR}mysqldump_tables.php db dump ../../");
    } else {
        if ($db->dbSystem() == "pgsql") {
            exit($c->error("Currently not supported on this platform."));
        }
    }
}
Пример #4
0
function populate_rt($table = '')
{
    $pdo = new DB();
    $rows = false;
    switch ($table) {
        case 'releases_rt':
            $pdo->queryDirect('SET SESSION group_concat_max_len=8192');
            $rows = $pdo->queryExec('SELECT r.id, r.name, r.searchname, r.fromname, IFNULL(GROUP_CONCAT(rf.name SEPARATOR " "),"") filename
				FROM releases r LEFT JOIN releasefiles rf ON(r.id=rf.releaseid) GROUP BY r.id');
            $rtvalues = '(id, name, searchname, fromname, filename)';
            break;
    }
    if ($rows !== false && ($total = $rows->rowCount())) {
        $sphinx = new SphinxSearch();
        $string = sprintf('REPLACE INTO %s %s VALUES ', $table, $rtvalues);
        $tempString = '';
        $i = 0;
        echo '[Starting to populate sphinx RT index ' . $table . ' with ' . $total . ' releases.] ';
        foreach ($rows as $row) {
            $i++;
            switch ($table) {
                case 'releases_rt':
                    $tempString .= sprintf('(%d, %s, %s, %s, %s),', $row['id'], $sphinx->sphinxQL->escapeString($row['name']), $sphinx->sphinxQL->escapeString($row['searchname']), $sphinx->sphinxQL->escapeString($row['fromname']), $sphinx->sphinxQL->escapeString($row['filename']));
                    break;
            }
            if ($i === 1000 || $i >= $total) {
                $sphinx->sphinxQL->queryExec($string . rtrim($tempString, ','));
                $tempString = '';
                $total -= $i;
                $i = 0;
                echo '.';
            }
        }
        echo ' [Done.]' . PHP_EOL;
    } else {
        echo 'No releases in your DB or an error occurred. This will need to be resolved before you can use the search.' . PHP_EOL;
    }
}
Пример #5
0
 public function updateItem($setting, $value)
 {
     $db = new DB();
     $sql = sprintf("update settings set value = %s where setting = %s", $db->escapeString($value), $db->escapeString($setting));
     return $db->exec($sql);
 }
Пример #6
0
    exit('Error, NN_RELEASE_SEARCH_TYPE in www/settings.php must be set to SPHINX!' . PHP_EOL);
}
$sphinxConnection = '';
if ($argc == 3 && is_numeric($argv[2])) {
    $sphinxConnection = sprintf('sphinx://%s:%d/', $argv[1], $argv[2]);
} elseif ($argc == 2) {
    // Checks that argv[1] exists AND that there are no other arguments, which would be an error.
    $socket = preg_replace('#^(?:unix://)?(.*)$#', '$1', $argv[1]);
    if (substr($socket, 0, 1) == '/') {
        // Make sure the socket path is fully qualified (and using correct separator).
        $sphinxConnection = sprintf('unix://%s:', $socket);
    }
} else {
    exit("Argument 1 must the hostname or IP to the Sphinx searchd server, Argument 2 must be the port to the Sphinx searchd server.\nAlternatively, Argument 1 can be a unix domain socket." . PHP_EOL);
}
$pdo = new DB();
$tableSQL_releases = <<<DDLSQL
CREATE TABLE releases_se
(
\tid          BIGINT UNSIGNED NOT NULL,
\tweight      INTEGER NOT NULL,
\tquery       VARCHAR(1024) NOT NULL,
\tname        VARCHAR(255) NOT NULL DEFAULT '',
\tsearchname  VARCHAR(255) NOT NULL DEFAULT '',
\tfromname    VARCHAR(255) NULL,
\tfilename    VARCHAR(1000) NULL,
\tINDEX(query)
) ENGINE=SPHINX CONNECTION="%sreleases_rt"
DDLSQL;
$tables = [];
$tables['releases_se'] = sprintf($tableSQL_releases, $sphinxConnection);