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

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