DbSearch-postgresql.php 2.9 KB

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