DbSearch-sqlite.php 2.7 KB

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