<?
function refresh_reindex($url) {
echo '<SCRIPT LANGUAGE="JavaScript">
<!--//
location.href = "'.$url.'";
//-->
</SCRIPT>
';
ui_end();
}
if(getoption('search','reindex') != '') {
$type = getoption('search','reindex');
}
if($type == 'client' || $type == 'product' || $type == 'message' || $type == 'page') {
set_time_limit(120);
setoption('search','reindex',$type);
$startpoint = getoption('search','index',-1);
if($startpoint == -1) {
print '<H1>Reindexing '.$type.' search data</H1>';
print '<H1>Begining work.</H1>';
bsql_query('DROP TABLE search_'.$type);
bsql_query('CREATE TABLE search_'.$type.'
(
s_o_id int(11) DEFAULT \'0\' NOT NULL,
s_word varchar(32) NOT NULL,
s_rank int(11) NOT NULL,
PRIMARY KEY (s_o_id,s_word),
KEY searchword (s_word)
)');
setoption('search','index',0);
setoption('search','starttime',time());
refresh_reindex($refreshurl);
}
$starttime = getoption('search','starttime');
$count = getoption('search','count',0);
switch($type) {
case 'client': $result = bsql_query('SELECT c_id FROM client_main
WHERE c_id > '.$startpoint.' AND c_group > 0 ORDER by c_id'); break;
case 'message': $result = bsql_query('SELECT mi_id FROM msg_info
WHERE mi_id > '.$startpoint.' ORDER by mi_id'); break;
case 'product': $result = bsql_query('SELECT p_id FROM product_main
WHERE p_id > '.$startpoint.' ORDER by p_id'); break;
case 'page': $result = bsql_query('SELECT p_id FROM page_main
WHERE p_id > '.$startpoint.' ORDER by p_id'); break;
}
$time = time()+10; $cnum = 0;
if($startpoint == 0) { setoption('search','total',bsql_numrows($result)); }
$total = getoption('search','total',0);
bsql_query('SET AUTOCOMMIT=0');
while(time() < $time && ($row = bsql_getrow($result))) {
$count++; $cnum++;
search_reindex($type,$row[0]);
}
bsql_query('COMMIT');
bsql_query('SET AUTOCOMMIT=1');
$thistime = time() - $time;
setoption('search','count',$count);
setoption('search','index',$row[0]);
if($count < $total) {
print '<H1>Reindexing '.$type.' search data</H1>';
print '<H1>Working..</H1>';
$completed = ($count * 100) / $total;
print '<H2>Completed '.intval($completed).'% (processed '.$cnum.' records last iteration)</H2>';
$time = (time() - $starttime);
$remtime = ($time * 100/$completed) - $time;
$mintaken = intval($time / 60);
$sectaken = $time % 60;
print "<H3>Time Taken: $mintaken minutes $sectaken seconds</H3>";
$minrem = intval($remtime / 60);
$secrem = $remtime % 60;
print "<H3>Est Time Remaining: $minrem minutes $secrem seconds</H3>";
refresh_reindex($refreshurl);
} else {
setoption('search','reindex','');
setoption('search','count',0);
setoption('search','index',-1);
setoption('search','total',0);
}
}
?>