DbSearch-mysql.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 2012 Simple Machines Forum 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('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_query')
  23. $smcFunc += array(
  24. 'db_search_query' => 'smf_db_query',
  25. 'db_search_support' => 'smf_db_search_support',
  26. 'db_create_word_search' => 'smf_db_create_word_search',
  27. 'db_support_ignore' => true,
  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('fulltext');
  38. return in_array($search_type, $supported_types);
  39. }
  40. /**
  41. * Highly specific function, to create the custom word index table.
  42. *
  43. * @param $size
  44. */
  45. function smf_db_create_word_search($size)
  46. {
  47. global $smcFunc;
  48. if ($size == 'small')
  49. $size = 'smallint(5)';
  50. elseif ($size == 'medium')
  51. $size = 'mediumint(8)';
  52. else
  53. $size = 'int(10)';
  54. $smcFunc['db_query']('', '
  55. CREATE TABLE {db_prefix}log_search_words (
  56. id_word {raw:size} unsigned NOT NULL default {string:string_zero},
  57. id_msg int(10) unsigned NOT NULL default {string:string_zero},
  58. PRIMARY KEY (id_word, id_msg)
  59. ) ENGINE=InnoDB',
  60. array(
  61. 'string_zero' => '0',
  62. 'size' => $size,
  63. )
  64. );
  65. }
  66. ?>