|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file contains database functions specific to search related activity. |
|
5
|
|
|
* |
|
6
|
|
|
* Simple Machines Forum (SMF) |
|
7
|
|
|
* |
|
8
|
|
|
* @package SMF |
|
9
|
|
|
* @author Simple Machines http://www.simplemachines.org |
|
10
|
|
|
* @copyright 2017 Simple Machines and individual contributors |
|
11
|
|
|
* @license http://www.simplemachines.org/about/smf/license.php BSD |
|
12
|
|
|
* |
|
13
|
|
|
* @version 2.1 Beta 4 |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
if (!defined('SMF')) |
|
17
|
|
|
die('No direct access...'); |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Add the file functions to the $smcFunc array. |
|
21
|
|
|
*/ |
|
22
|
|
|
function db_search_init() |
|
23
|
|
|
{ |
|
24
|
|
|
global $smcFunc; |
|
25
|
|
|
|
|
26
|
|
View Code Duplication |
if (!isset($smcFunc['db_search_query']) || $smcFunc['db_search_query'] != 'smf_db_query') |
|
|
|
|
|
|
27
|
|
|
$smcFunc += array( |
|
28
|
|
|
'db_search_query' => 'smf_db_query', |
|
29
|
|
|
'db_search_support' => 'smf_db_search_support', |
|
30
|
|
|
'db_create_word_search' => 'smf_db_create_word_search', |
|
31
|
|
|
'db_support_ignore' => true, |
|
32
|
|
|
); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* This function will tell you whether this database type supports this search type. |
|
37
|
|
|
* |
|
38
|
|
|
* @param string $search_type The search type. |
|
39
|
|
|
* @return boolean Whether or not the specified search type is supported by this db system |
|
40
|
|
|
*/ |
|
41
|
|
|
function smf_db_search_support($search_type) |
|
42
|
|
|
{ |
|
43
|
|
|
$supported_types = array('fulltext'); |
|
44
|
|
|
|
|
45
|
|
|
return in_array($search_type, $supported_types); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Highly specific function, to create the custom word index table. |
|
50
|
|
|
* |
|
51
|
|
|
* @param string $size The size of the desired index. |
|
52
|
|
|
*/ |
|
53
|
|
|
function smf_db_create_word_search($size) |
|
|
|
|
|
|
54
|
|
|
{ |
|
55
|
|
|
global $smcFunc; |
|
56
|
|
|
|
|
57
|
|
|
if ($size == 'small') |
|
58
|
|
|
$size = 'smallint(5)'; |
|
59
|
|
|
elseif ($size == 'medium') |
|
60
|
|
|
$size = 'mediumint(8)'; |
|
61
|
|
|
else |
|
62
|
|
|
$size = 'int(10)'; |
|
63
|
|
|
|
|
64
|
|
|
$smcFunc['db_query']('', ' |
|
65
|
|
|
CREATE TABLE {db_prefix}log_search_words ( |
|
66
|
|
|
id_word {raw:size} unsigned NOT NULL default {string:string_zero}, |
|
67
|
|
|
id_msg int(10) unsigned NOT NULL default {string:string_zero}, |
|
68
|
|
|
PRIMARY KEY (id_word, id_msg) |
|
69
|
|
|
) ENGINE=InnoDB', |
|
70
|
|
|
array( |
|
71
|
|
|
'string_zero' => '0', |
|
72
|
|
|
'size' => $size, |
|
73
|
|
|
) |
|
74
|
|
|
); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
?> |
|
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.