DbSearch-postgresql.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. '~unsigned~i' => '',
  50. '~TYPE=HEAP~i' => '',
  51. ),
  52. 'create_tmp_log_search_messages' => array(
  53. '~mediumint\(\d\)' => 'int',
  54. '~unsigned~i' => '',
  55. '~TYPE=HEAP~i' => '',
  56. ),
  57. 'drop_tmp_log_search_topics' => array(
  58. '~IF\sEXISTS~i' => '',
  59. ),
  60. 'drop_tmp_log_search_messages' => array(
  61. '~IF\sEXISTS~i' => '',
  62. ),
  63. 'insert_into_log_messages_fulltext' => array(
  64. '~NOT\sRLIKE~i' => '!~*',
  65. '~RLIKE~i' => '~*',
  66. ),
  67. 'insert_log_search_results_subject' => array(
  68. '~NOT\sRLIKE~i' => '!~*',
  69. '~RLIKE~i' => '~*',
  70. ),
  71. );
  72. if (isset($replacements[$identifier]))
  73. $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
  74. elseif (preg_match('~^\s*INSERT\sIGNORE~i', $db_string) != 0)
  75. {
  76. $db_string = preg_replace('~^\s*INSERT\sIGNORE~i', 'INSERT', $db_string);
  77. // Don't error on multi-insert.
  78. $db_values['db_error_skip'] = true;
  79. }
  80. $return = $smcFunc['db_query']('', $db_string,
  81. $db_values, $connection
  82. );
  83. return $return;
  84. }
  85. // Highly specific - create the custom word index table!
  86. function smf_db_create_word_search($size)
  87. {
  88. global $smcFunc;
  89. $size = 'int';
  90. $smcFunc['db_query']('', '
  91. CREATE TABLE {db_prefix}log_search_words (
  92. id_word {raw:size} NOT NULL default {string:string_zero},
  93. id_msg int NOT NULL default {string:string_zero},
  94. PRIMARY KEY (id_word, id_msg)
  95. )',
  96. array(
  97. 'size' => $size,
  98. 'string_zero' => '0',
  99. )
  100. );
  101. }
  102. ?>