DbSearch-postgresql.php 3.4 KB

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