2013-07-10 00:08:53 +00:00
|
|
|
<?php
|
2013-05-04 08:00:48 +00:00
|
|
|
if (!empty($_GET['page']) && is_number($_GET['page'])) {
|
|
|
|
$Page = min(SPHINX_MAX_MATCHES / LOG_ENTRIES_PER_PAGE, $_GET['page']);
|
|
|
|
$Offset = ($Page - 1) * LOG_ENTRIES_PER_PAGE;
|
2012-08-31 08:00:22 +00:00
|
|
|
} else {
|
|
|
|
$Page = 1;
|
|
|
|
$Offset = 0;
|
|
|
|
}
|
2013-05-04 08:00:48 +00:00
|
|
|
if (empty($_GET['search']) || trim($_GET['search']) == '') {
|
2013-07-10 00:08:53 +00:00
|
|
|
$Log = $DB->query("
|
|
|
|
SELECT ID, Message, Time
|
|
|
|
FROM log
|
|
|
|
ORDER BY ID DESC
|
|
|
|
LIMIT $Offset, ".LOG_ENTRIES_PER_PAGE);
|
2012-08-31 08:00:22 +00:00
|
|
|
$NumResults = $DB->record_count();
|
2013-05-04 08:00:48 +00:00
|
|
|
if (!$NumResults) {
|
2012-08-31 08:00:22 +00:00
|
|
|
$TotalMatches = 0;
|
2013-05-04 08:00:48 +00:00
|
|
|
} elseif ($NumResults == LOG_ENTRIES_PER_PAGE) {
|
2012-08-31 08:00:22 +00:00
|
|
|
// This is a lot faster than SQL_CALC_FOUND_ROWS
|
2013-03-17 08:00:17 +00:00
|
|
|
$SphQL = new SphinxqlQuery();
|
2012-08-31 08:00:22 +00:00
|
|
|
$Result = $SphQL->select('id')->from('log, log_delta')->limit(0, 1, 1)->query();
|
|
|
|
$Debug->log_var($Result, '$Result');
|
|
|
|
$TotalMatches = min(SPHINX_MAX_MATCHES, $Result->get_meta('total_found'));
|
|
|
|
} else {
|
|
|
|
$TotalMatches = $NumResults + $Offset;
|
|
|
|
}
|
|
|
|
$QueryStatus = 0;
|
|
|
|
} else {
|
2013-12-13 08:00:46 +00:00
|
|
|
|
2013-05-04 08:00:48 +00:00
|
|
|
$Page = min(SPHINX_MAX_MATCHES / TORRENTS_PER_PAGE, $Page);
|
2013-03-17 08:00:17 +00:00
|
|
|
$SphQL = new SphinxqlQuery();
|
2012-08-31 08:00:22 +00:00
|
|
|
$SphQL->select('id')
|
|
|
|
->from('log, log_delta')
|
|
|
|
->where_match($_GET['search'], 'message')
|
2012-10-07 08:00:25 +00:00
|
|
|
->order_by('id', 'DESC')
|
2013-05-04 08:00:48 +00:00
|
|
|
->limit($Offset, LOG_ENTRIES_PER_PAGE, $Offset + LOG_ENTRIES_PER_PAGE);
|
2012-08-31 08:00:22 +00:00
|
|
|
|
|
|
|
$Result = $SphQL->query();
|
|
|
|
$Debug->log_var($Result, '$Result');
|
|
|
|
$Debug->set_flag('Finished SphQL query');
|
2013-05-04 08:00:48 +00:00
|
|
|
if ($QueryStatus = $Result->Errno) {
|
2012-08-31 08:00:22 +00:00
|
|
|
$QueryError = $Result->Error;
|
|
|
|
}
|
|
|
|
$NumResults = $Result->get_result_info('num_rows');
|
|
|
|
$TotalMatches = min(SPHINX_MAX_MATCHES, $Result->get_meta('total_found'));
|
2013-05-04 08:00:48 +00:00
|
|
|
if ($NumResults > 0) {
|
2012-08-31 08:00:22 +00:00
|
|
|
$LogIDs = $Result->collect('id');
|
2013-07-10 00:08:53 +00:00
|
|
|
$Log = $DB->query('
|
|
|
|
SELECT ID, Message, Time
|
|
|
|
FROM log
|
|
|
|
WHERE ID IN ('.implode(',', $LogIDs).')
|
|
|
|
ORDER BY ID DESC');
|
2012-08-31 08:00:22 +00:00
|
|
|
} else {
|
2013-07-10 00:08:53 +00:00
|
|
|
$Log = $DB->query('
|
|
|
|
SET @nothing = 0');
|
2012-08-31 08:00:22 +00:00
|
|
|
}
|
|
|
|
}
|