BioTorrents.de’s version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sphinx.php 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. if (!empty($_GET['page']) && is_number($_GET['page'])) {
  3. $Page = min(SPHINX_MAX_MATCHES / LOG_ENTRIES_PER_PAGE, $_GET['page']);
  4. $Offset = ($Page - 1) * LOG_ENTRIES_PER_PAGE;
  5. } else {
  6. $Page = 1;
  7. $Offset = 0;
  8. }
  9. if (empty($_GET['search']) || trim($_GET['search']) === '') {
  10. $Log = $DB->query(
  11. "
  12. SELECT
  13. `ID`,
  14. `Message`,
  15. `Time`
  16. FROM
  17. `log`
  18. ORDER BY
  19. `ID`
  20. DESC
  21. LIMIT $Offset, ".LOG_ENTRIES_PER_PAGE
  22. );
  23. $NumResults = $DB->record_count();
  24. if (!$NumResults) {
  25. $TotalMatches = 0;
  26. } elseif ($NumResults === LOG_ENTRIES_PER_PAGE) {
  27. // This is a lot faster than SQL_CALC_FOUND_ROWS
  28. $SphQL = new SphinxqlQuery();
  29. $Result = $SphQL->select('id')->from('log, log_delta')->limit(0, 1, 1)->query();
  30. $Debug->log_var($Result, '$Result');
  31. $TotalMatches = min(SPHINX_MAX_MATCHES, $Result->get_meta('total_found'));
  32. } else {
  33. $TotalMatches = $NumResults + $Offset;
  34. }
  35. $QueryStatus = 0;
  36. } else {
  37. $Page = min(SPHINX_MAX_MATCHES / TORRENTS_PER_PAGE, $Page);
  38. $SphQL = new SphinxqlQuery();
  39. $SphQL->select('id')
  40. ->from('log, log_delta')
  41. ->where_match($_GET['search'], 'message')
  42. ->order_by('id', 'DESC')
  43. ->limit($Offset, LOG_ENTRIES_PER_PAGE, $Offset + LOG_ENTRIES_PER_PAGE);
  44. $Result = $SphQL->query();
  45. $Debug->log_var($Result, '$Result');
  46. $Debug->set_flag('Finished SphQL query');
  47. if ($QueryStatus = $Result->Errno) {
  48. $QueryError = $Result->Error;
  49. }
  50. $NumResults = $Result->get_result_info('num_rows');
  51. $TotalMatches = min(SPHINX_MAX_MATCHES, $Result->get_meta('total_found'));
  52. if ($NumResults > 0) {
  53. $LogIDs = $Result->collect('id');
  54. $Log = $DB->query("
  55. SELECT
  56. `ID`,
  57. `Message`,
  58. `Time`
  59. FROM
  60. `log`
  61. WHERE
  62. `ID` IN(".implode(',', $LogIDs).")
  63. ORDER BY
  64. `ID`
  65. DESC
  66. ");
  67. } else {
  68. $Log = $DB->query("SET @nothing = 0");
  69. }
  70. }