DbSearch-sqlite.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 2014 Simple Machines and individual 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('No direct access...');
  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 The search type.
  34. * @return boolean Whether or not the specified search type is supported by this DB system.
  35. */
  36. function smf_db_search_support($search_type)
  37. {
  38. $supported_types = array('custom');
  39. return in_array($search_type, $supported_types);
  40. }
  41. /**
  42. * Returns the correct query for this search type.
  43. *
  44. * @param string $identifier A query identifier
  45. * @param string $db_string The query text
  46. * @param array $db_values An array of values to pass to $smcFunc['db_query']
  47. * @param resource $connection The current DB connection resource
  48. * @return resource The query result resource from $smcFunc['db_query']
  49. */
  50. function smf_db_search_query($identifier, $db_string, $db_values = array(), $connection = null)
  51. {
  52. global $smcFunc;
  53. $replacements = array(
  54. 'create_tmp_log_search_topics' => array(
  55. '~mediumint\(\d\)~i' => 'int',
  56. '~ENGINE=MEMORY~i' => '',
  57. ),
  58. 'create_tmp_log_search_messages' => array(
  59. '~mediumint\(\d\)~i' => 'int',
  60. '~ENGINE=MEMORY~i' => '',
  61. ),
  62. );
  63. if (isset($replacements[$identifier]))
  64. $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
  65. elseif (preg_match('~^\s*INSERT\sIGNORE~i', $db_string) != 0)
  66. {
  67. $db_string = preg_replace('~^\s*INSERT\sIGNORE~i', 'INSERT', $db_string);
  68. // Don't error on multi-insert.
  69. $db_values['db_error_skip'] = true;
  70. }
  71. $return = $smcFunc['db_query']('', $db_string,
  72. $db_values, $connection
  73. );
  74. return $return;
  75. }
  76. /**
  77. * Highly specific function, to create the custom word index table.
  78. *
  79. * @param string $size The column size type (int, mediumint (8), etc.). Not used here.
  80. */
  81. function smf_db_create_word_search($size)
  82. {
  83. global $smcFunc;
  84. $size = 'int';
  85. $smcFunc['db_query']('', '
  86. CREATE TABLE {db_prefix}log_search_words (
  87. id_word {raw:size} NOT NULL default {string:string_zero},
  88. id_msg int(10) NOT NULL default {string:string_zero},
  89. PRIMARY KEY (id_word, id_msg)
  90. )',
  91. array(
  92. 'size' => $size,
  93. 'string_zero' => '0',
  94. )
  95. );
  96. }
  97. ?>