DbSearch-postgresql.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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
  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. '~LIKE~i' => 'iLIKE',
  70. '~NOT\sLIKE~i' => '~NOT iLIKE',
  71. '~NOT\sRLIKE~i' => '!~*',
  72. '~RLIKE~i' => '~*',
  73. ),
  74. 'insert_log_search_results_subject' => array(
  75. '~LIKE~i' => 'iLIKE',
  76. '~NOT\sLIKE~i' => 'NOT iLIKE',
  77. '~NOT\sRLIKE~i' => '!~*',
  78. '~RLIKE~i' => '~*',
  79. ),
  80. );
  81. if (isset($replacements[$identifier]))
  82. $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
  83. elseif (preg_match('~^\s*INSERT\sIGNORE~i', $db_string) != 0)
  84. {
  85. $db_string = preg_replace('~^\s*INSERT\sIGNORE~i', 'INSERT', $db_string);
  86. // Don't error on multi-insert.
  87. $db_values['db_error_skip'] = true;
  88. }
  89. $return = $smcFunc['db_query']('', $db_string,
  90. $db_values, $connection
  91. );
  92. return $return;
  93. }
  94. /**
  95. * Highly specific function, to create the custom word index table.
  96. *
  97. * @param $size
  98. */
  99. function smf_db_create_word_search($size)
  100. {
  101. global $smcFunc;
  102. $size = 'int';
  103. $smcFunc['db_query']('', '
  104. CREATE TABLE {db_prefix}log_search_words (
  105. id_word {raw:size} NOT NULL default {string:string_zero},
  106. id_msg int NOT NULL default {string:string_zero},
  107. PRIMARY KEY (id_word, id_msg)
  108. )',
  109. array(
  110. 'size' => $size,
  111. 'string_zero' => '0',
  112. )
  113. );
  114. }
  115. ?>