DbSearch-mysql.php 1.8 KB

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