DbSearch-sqlite.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /**
  3. * This file contains database functions specific to search related activity.
  4. *
  5. * Simple Machines Forum (SMF)
  6. *
  7. * @package SMF
  8. * @author Simple Machines http://www.simplemachines.org
  9. * @copyright 2012 Simple Machines Forum contributors
  10. * @license http://www.simplemachines.org/about/smf/license.php BSD
  11. *
  12. * @version 2.1 Alpha 1
  13. */
  14. if (!defined('SMF'))
  15. die('Hacking attempt...');
  16. /**
  17. * Add the file functions to the $smcFunc array.
  18. */
  19. function db_search_init()
  20. {
  21. global $smcFunc;
  22. if (!isset($smcFunc['db_search_query']) || $smcFunc['db_search_query'] != 'smf_db_search_query')
  23. $smcFunc += array(
  24. 'db_search_query' => 'smf_db_search_query',
  25. 'db_search_support' => 'smf_db_search_support',
  26. 'db_create_word_search' => 'smf_db_create_word_search',
  27. 'db_support_ignore' => false,
  28. );
  29. }
  30. /**
  31. * This function will tell you whether this database type supports this search type.
  32. *
  33. * @param string $search_type
  34. */
  35. function smf_db_search_support($search_type)
  36. {
  37. $supported_types = array('custom');
  38. return in_array($search_type, $supported_types);
  39. }
  40. /**
  41. * Returns the correct query for this search type.
  42. *
  43. * @param string $identifier
  44. * @param string $db_string
  45. * @param array $db_values, default array()
  46. * @param resource $connection
  47. */
  48. function smf_db_search_query($identifier, $db_string, $db_values = array(), $connection = null)
  49. {
  50. global $smcFunc;
  51. $replacements = array(
  52. 'create_tmp_log_search_topics' => array(
  53. '~mediumint\(\d\)~i' => 'int',
  54. '~TYPE=HEAP~i' => '',
  55. ),
  56. 'create_tmp_log_search_messages' => array(
  57. '~mediumint\(\d\)~i' => 'int',
  58. '~TYPE=HEAP~i' => '',
  59. ),
  60. );
  61. if (isset($replacements[$identifier]))
  62. $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
  63. elseif (preg_match('~^\s*INSERT\sIGNORE~i', $db_string) != 0)
  64. {
  65. $db_string = preg_replace('~^\s*INSERT\sIGNORE~i', 'INSERT', $db_string);
  66. // Don't error on multi-insert.
  67. $db_values['db_error_skip'] = true;
  68. }
  69. $return = $smcFunc['db_query']('', $db_string,
  70. $db_values, $connection
  71. );
  72. return $return;
  73. }
  74. /**
  75. * Highly specific function, to create the custom word index table.
  76. *
  77. * @param $size
  78. */
  79. function smf_db_create_word_search($size)
  80. {
  81. global $smcFunc;
  82. $size = 'int';
  83. $smcFunc['db_query']('', '
  84. CREATE TABLE {db_prefix}log_search_words (
  85. id_word {raw:size} NOT NULL default {string:string_zero},
  86. id_msg int(10) NOT NULL default {string:string_zero},
  87. PRIMARY KEY (id_word, id_msg)
  88. )',
  89. array(
  90. 'size' => $size,
  91. 'string_zero' => '0',
  92. )
  93. );
  94. }
  95. ?>