mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-29 01:08:56 +00:00
65 lines
1.9 KiB
PHP
65 lines
1.9 KiB
PHP
<?php
|
|
require dirname(__FILE__) . '/../../www/config.php';
|
|
|
|
use newznab\db\DB;
|
|
|
|
if (NN_RELEASE_SEARCH_TYPE != ReleaseSearch::SPHINX) {
|
|
exit('Error, NN_RELEASE_SEARCH_TYPE in www/settings.php must be set to SPHINX!' . PHP_EOL);
|
|
} else if (!isset($argv[1]) || !in_array($argv[1], ['releases_rt'])) {
|
|
exit('Argument1 is the index name, releases_rt are the only supported ones currently.' . PHP_EOL);
|
|
} else {
|
|
populate_rt($argv[1]);
|
|
}
|
|
|
|
// Bulk insert releases into sphinx RT index.
|
|
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;
|
|
}
|
|
} |