@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | |
| 207 | 207 | if (!empty($modSettings['search_simple_fulltext'])) |
| 208 | 208 | { |
| 209 | - if($smcFunc['db_title'] == "PostgreSQL") |
|
| 209 | + if ($smcFunc['db_title'] == "PostgreSQL") |
|
| 210 | 210 | { |
| 211 | 211 | $language_ftx = $smcFunc['db_search_language'](); |
| 212 | 212 | |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | // remove any indexed words that are used in the complex body search terms |
| 225 | 225 | $words['indexed_words'] = array_diff($words['indexed_words'], $words['complex_words']); |
| 226 | 226 | |
| 227 | - if($smcFunc['db_title'] == "PostgreSQL"){ |
|
| 227 | + if ($smcFunc['db_title'] == "PostgreSQL") { |
|
| 228 | 228 | $row = 0; |
| 229 | 229 | foreach ($words['indexed_words'] as $fulltextWord) { |
| 230 | 230 | $query_params['boolean_match'] .= ($row <> 0 ? '&' : ''); |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | |
| 241 | 241 | // if we have bool terms to search, add them in |
| 242 | 242 | if ($query_params['boolean_match']) { |
| 243 | - if($smcFunc['db_title'] == "PostgreSQL") |
|
| 243 | + if ($smcFunc['db_title'] == "PostgreSQL") |
|
| 244 | 244 | { |
| 245 | 245 | $language_ftx = $smcFunc['db_search_language'](); |
| 246 | 246 | |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | - $ignoreRequest = $smcFunc['db_search_query']('insert_into_log_messages_fulltext', ($smcFunc['db_support_ignore'] ? ( ' |
|
| 256 | + $ignoreRequest = $smcFunc['db_search_query']('insert_into_log_messages_fulltext', ($smcFunc['db_support_ignore'] ? (' |
|
| 257 | 257 | INSERT IGNORE INTO {db_prefix}' . $search_data['insert_into'] . ' |
| 258 | 258 | (' . implode(', ', array_keys($query_select)) . ')') : '') . ' |
| 259 | 259 | SELECT ' . implode(', ', $query_select) . ' |
@@ -11,8 +11,9 @@ discard block |
||
| 11 | 11 | * @version 2.1 Beta 3 |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | -if (!defined('SMF')) |
|
| 14 | +if (!defined('SMF')) { |
|
| 15 | 15 | die('No direct access...'); |
| 16 | +} |
|
| 16 | 17 | |
| 17 | 18 | /** |
| 18 | 19 | * Class fulltext_search |
@@ -98,8 +99,9 @@ discard block |
||
| 98 | 99 | $smcFunc['db_free_result']($request); |
| 99 | 100 | } |
| 100 | 101 | // 4 is the MySQL default... |
| 101 | - else |
|
| 102 | - $min_word_length = 4; |
|
| 102 | + else { |
|
| 103 | + $min_word_length = 4; |
|
| 104 | + } |
|
| 103 | 105 | |
| 104 | 106 | return $min_word_length; |
| 105 | 107 | } |
@@ -138,8 +140,7 @@ discard block |
||
| 138 | 140 | $wordsSearch['words'][] = trim($word, "/*- "); |
| 139 | 141 | $wordsSearch['complex_words'][] = count($subwords) === 1 ? $word : '"' . $word . '"'; |
| 140 | 142 | } |
| 141 | - } |
|
| 142 | - elseif ($smcFunc['strlen'](trim($word, "/*- ")) < $this->min_word_length) |
|
| 143 | + } elseif ($smcFunc['strlen'](trim($word, "/*- ")) < $this->min_word_length) |
|
| 143 | 144 | { |
| 144 | 145 | // short words have feelings too |
| 145 | 146 | $wordsSearch['words'][] = trim($word, "/*- "); |
@@ -149,8 +150,9 @@ discard block |
||
| 149 | 150 | |
| 150 | 151 | $fulltextWord = count($subwords) === 1 ? $word : '"' . $word . '"'; |
| 151 | 152 | $wordsSearch['indexed_words'][] = $fulltextWord; |
| 152 | - if ($isExcluded) |
|
| 153 | - $wordsExclude[] = $fulltextWord; |
|
| 153 | + if ($isExcluded) { |
|
| 154 | + $wordsExclude[] = $fulltextWord; |
|
| 155 | + } |
|
| 154 | 156 | } |
| 155 | 157 | |
| 156 | 158 | /** |
@@ -166,41 +168,50 @@ discard block |
||
| 166 | 168 | $query_where = array(); |
| 167 | 169 | $query_params = $search_data['params']; |
| 168 | 170 | |
| 169 | - if ($query_params['id_search']) |
|
| 170 | - $query_select['id_search'] = '{int:id_search}'; |
|
| 171 | + if ($query_params['id_search']) { |
|
| 172 | + $query_select['id_search'] = '{int:id_search}'; |
|
| 173 | + } |
|
| 171 | 174 | |
| 172 | 175 | $count = 0; |
| 173 | - if (empty($modSettings['search_simple_fulltext'])) |
|
| 174 | - foreach ($words['words'] as $regularWord) |
|
| 176 | + if (empty($modSettings['search_simple_fulltext'])) { |
|
| 177 | + foreach ($words['words'] as $regularWord) |
|
| 175 | 178 | { |
| 176 | 179 | $query_where[] = 'm.body' . (in_array($regularWord, $query_params['excluded_words']) ? ' NOT' : '') . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:complex_body_' . $count . '}'; |
| 180 | + } |
|
| 177 | 181 | $query_params['complex_body_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($regularWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $regularWord), '\\\'') . '[[:>:]]'; |
| 178 | 182 | } |
| 179 | 183 | |
| 180 | - if ($query_params['user_query']) |
|
| 181 | - $query_where[] = '{raw:user_query}'; |
|
| 182 | - if ($query_params['board_query']) |
|
| 183 | - $query_where[] = 'm.id_board {raw:board_query}'; |
|
| 184 | + if ($query_params['user_query']) { |
|
| 185 | + $query_where[] = '{raw:user_query}'; |
|
| 186 | + } |
|
| 187 | + if ($query_params['board_query']) { |
|
| 188 | + $query_where[] = 'm.id_board {raw:board_query}'; |
|
| 189 | + } |
|
| 184 | 190 | |
| 185 | - if ($query_params['topic']) |
|
| 186 | - $query_where[] = 'm.id_topic = {int:topic}'; |
|
| 187 | - if ($query_params['min_msg_id']) |
|
| 188 | - $query_where[] = 'm.id_msg >= {int:min_msg_id}'; |
|
| 189 | - if ($query_params['max_msg_id']) |
|
| 190 | - $query_where[] = 'm.id_msg <= {int:max_msg_id}'; |
|
| 191 | + if ($query_params['topic']) { |
|
| 192 | + $query_where[] = 'm.id_topic = {int:topic}'; |
|
| 193 | + } |
|
| 194 | + if ($query_params['min_msg_id']) { |
|
| 195 | + $query_where[] = 'm.id_msg >= {int:min_msg_id}'; |
|
| 196 | + } |
|
| 197 | + if ($query_params['max_msg_id']) { |
|
| 198 | + $query_where[] = 'm.id_msg <= {int:max_msg_id}'; |
|
| 199 | + } |
|
| 191 | 200 | |
| 192 | 201 | $count = 0; |
| 193 | - if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) |
|
| 194 | - foreach ($query_params['excluded_phrases'] as $phrase) |
|
| 202 | + if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) { |
|
| 203 | + foreach ($query_params['excluded_phrases'] as $phrase) |
|
| 195 | 204 | { |
| 196 | 205 | $query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:exclude_subject_phrase_' . $count . '}'; |
| 206 | + } |
|
| 197 | 207 | $query_params['exclude_subject_phrase_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($phrase, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $phrase), '\\\'') . '[[:>:]]'; |
| 198 | 208 | } |
| 199 | 209 | $count = 0; |
| 200 | - if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) |
|
| 201 | - foreach ($query_params['excluded_subject_words'] as $excludedWord) |
|
| 210 | + if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) { |
|
| 211 | + foreach ($query_params['excluded_subject_words'] as $excludedWord) |
|
| 202 | 212 | { |
| 203 | 213 | $query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:exclude_subject_words_' . $count . '}'; |
| 214 | + } |
|
| 204 | 215 | $query_params['exclude_subject_words_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($excludedWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $excludedWord), '\\\'') . '[[:>:]]'; |
| 205 | 216 | } |
| 206 | 217 | |
@@ -212,12 +223,11 @@ discard block |
||
| 212 | 223 | |
| 213 | 224 | $query_where[] = 'to_tsvector({string:language_ftx},body) @@ to_tsquery({string:language_ftx},{string:body_match})'; |
| 214 | 225 | $query_params['language_ftx'] = $language_ftx; |
| 226 | + } else { |
|
| 227 | + $query_where[] = 'MATCH (body) AGAINST ({string:body_match})'; |
|
| 215 | 228 | } |
| 216 | - else |
|
| 217 | - $query_where[] = 'MATCH (body) AGAINST ({string:body_match})'; |
|
| 218 | 229 | $query_params['body_match'] = implode(' ', array_diff($words['indexed_words'], $query_params['excluded_index_words'])); |
| 219 | - } |
|
| 220 | - else |
|
| 230 | + } else |
|
| 221 | 231 | { |
| 222 | 232 | $query_params['boolean_match'] = ''; |
| 223 | 233 | |
@@ -231,10 +241,10 @@ discard block |
||
| 231 | 241 | $query_params['boolean_match'] .= (in_array($fulltextWord, $query_params['excluded_index_words']) ? '!' : '') . $fulltextWord . ' '; |
| 232 | 242 | $row++; |
| 233 | 243 | } |
| 234 | - } |
|
| 235 | - else |
|
| 236 | - foreach ($words['indexed_words'] as $fulltextWord) |
|
| 244 | + } else { |
|
| 245 | + foreach ($words['indexed_words'] as $fulltextWord) |
|
| 237 | 246 | $query_params['boolean_match'] .= (in_array($fulltextWord, $query_params['excluded_index_words']) ? '-' : '+') . $fulltextWord . ' '; |
| 247 | + } |
|
| 238 | 248 | |
| 239 | 249 | $query_params['boolean_match'] = substr($query_params['boolean_match'], 0, -1); |
| 240 | 250 | |
@@ -246,9 +256,9 @@ discard block |
||
| 246 | 256 | |
| 247 | 257 | $query_where[] = 'to_tsvector({string:language_ftx},body) @@ to_tsquery({string:language_ftx},{string:boolean_match})'; |
| 248 | 258 | $query_params['language_ftx'] = $language_ftx; |
| 259 | + } else { |
|
| 260 | + $query_where[] = 'MATCH (body) AGAINST ({string:boolean_match} IN BOOLEAN MODE)'; |
|
| 249 | 261 | } |
| 250 | - else |
|
| 251 | - $query_where[] = 'MATCH (body) AGAINST ({string:boolean_match} IN BOOLEAN MODE)'; |
|
| 252 | 262 | } |
| 253 | 263 | |
| 254 | 264 | } |
@@ -38,12 +38,12 @@ discard block |
||
| 38 | 38 | $version = $smcFunc['db_get_version'](); |
| 39 | 39 | // if we got a Beta Version |
| 40 | 40 | if (stripos($version, 'beta') !== false) |
| 41 | - $version = substr($version, 0, stripos($version, 'beta')).'.0'; |
|
| 41 | + $version = substr($version, 0, stripos($version, 'beta')) . '.0'; |
|
| 42 | 42 | // or RC |
| 43 | 43 | if (stripos($version, 'rc') !== false) |
| 44 | - $version = substr($version, 0, stripos($version, 'rc')).'.0'; |
|
| 44 | + $version = substr($version, 0, stripos($version, 'rc')) . '.0'; |
|
| 45 | 45 | |
| 46 | - if (version_compare($version,'9.5.0','>=')) |
|
| 46 | + if (version_compare($version, '9.5.0', '>=')) |
|
| 47 | 47 | $smcFunc['db_support_ignore'] = true; |
| 48 | 48 | } |
| 49 | 49 | |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | function smf_db_search_support($search_type) |
| 57 | 57 | { |
| 58 | - $supported_types = array('custom','fulltext'); |
|
| 58 | + $supported_types = array('custom', 'fulltext'); |
|
| 59 | 59 | |
| 60 | 60 | return in_array($search_type, $supported_types); |
| 61 | 61 | } |
@@ -109,9 +109,9 @@ discard block |
||
| 109 | 109 | if (preg_match('~^\s*INSERT\sIGNORE~i', $db_string) != 0) |
| 110 | 110 | { |
| 111 | 111 | $db_string = preg_replace('~^\s*INSERT\sIGNORE~i', 'INSERT', $db_string); |
| 112 | - if ($smcFunc['db_support_ignore']){ |
|
| 112 | + if ($smcFunc['db_support_ignore']) { |
|
| 113 | 113 | //pg style "INSERT INTO.... ON CONFLICT DO NOTHING" |
| 114 | - $db_string = $db_string.' ON CONFLICT DO NOTHING'; |
|
| 114 | + $db_string = $db_string . ' ON CONFLICT DO NOTHING'; |
|
| 115 | 115 | } |
| 116 | 116 | else |
| 117 | 117 | { |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | $language_ftx = $modSettings['search_language']; |
| 169 | 169 | else |
| 170 | 170 | { |
| 171 | - $request = $smcFunc['db_query']('',' |
|
| 171 | + $request = $smcFunc['db_query']('', ' |
|
| 172 | 172 | SHOW default_text_search_config', |
| 173 | 173 | array() |
| 174 | 174 | ); |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 3 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Add the file functions to the $smcFunc array. |
@@ -23,29 +24,33 @@ discard block |
||
| 23 | 24 | { |
| 24 | 25 | global $smcFunc; |
| 25 | 26 | |
| 26 | - if (!isset($smcFunc['db_search_query']) || $smcFunc['db_search_query'] != 'smf_db_search_query') |
|
| 27 | - $smcFunc += array( |
|
| 27 | + if (!isset($smcFunc['db_search_query']) || $smcFunc['db_search_query'] != 'smf_db_search_query') { |
|
| 28 | + $smcFunc += array( |
|
| 28 | 29 | 'db_search_query' => 'smf_db_search_query', |
| 29 | 30 | 'db_search_support' => 'smf_db_search_support', |
| 30 | 31 | 'db_create_word_search' => 'smf_db_create_word_search', |
| 31 | 32 | 'db_support_ignore' => false, |
| 32 | 33 | 'db_search_language' => 'smf_db_search_language', |
| 33 | 34 | ); |
| 35 | + } |
|
| 34 | 36 | |
| 35 | 37 | db_extend(); |
| 36 | 38 | |
| 37 | 39 | //pg 9.5 got ignore support |
| 38 | 40 | $version = $smcFunc['db_get_version'](); |
| 39 | 41 | // if we got a Beta Version |
| 40 | - if (stripos($version, 'beta') !== false) |
|
| 41 | - $version = substr($version, 0, stripos($version, 'beta')).'.0'; |
|
| 42 | + if (stripos($version, 'beta') !== false) { |
|
| 43 | + $version = substr($version, 0, stripos($version, 'beta')).'.0'; |
|
| 44 | + } |
|
| 42 | 45 | // or RC |
| 43 | - if (stripos($version, 'rc') !== false) |
|
| 44 | - $version = substr($version, 0, stripos($version, 'rc')).'.0'; |
|
| 46 | + if (stripos($version, 'rc') !== false) { |
|
| 47 | + $version = substr($version, 0, stripos($version, 'rc')).'.0'; |
|
| 48 | + } |
|
| 45 | 49 | |
| 46 | - if (version_compare($version,'9.5.0','>=')) |
|
| 47 | - $smcFunc['db_support_ignore'] = true; |
|
| 48 | -} |
|
| 50 | + if (version_compare($version,'9.5.0','>=')) { |
|
| 51 | + $smcFunc['db_support_ignore'] = true; |
|
| 52 | + } |
|
| 53 | + } |
|
| 49 | 54 | |
| 50 | 55 | /** |
| 51 | 56 | * This function will tell you whether this database type supports this search type. |
@@ -104,16 +109,16 @@ discard block |
||
| 104 | 109 | ), |
| 105 | 110 | ); |
| 106 | 111 | |
| 107 | - if (isset($replacements[$identifier])) |
|
| 108 | - $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
| 112 | + if (isset($replacements[$identifier])) { |
|
| 113 | + $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
| 114 | + } |
|
| 109 | 115 | if (preg_match('~^\s*INSERT\sIGNORE~i', $db_string) != 0) |
| 110 | 116 | { |
| 111 | 117 | $db_string = preg_replace('~^\s*INSERT\sIGNORE~i', 'INSERT', $db_string); |
| 112 | 118 | if ($smcFunc['db_support_ignore']){ |
| 113 | 119 | //pg style "INSERT INTO.... ON CONFLICT DO NOTHING" |
| 114 | 120 | $db_string = $db_string.' ON CONFLICT DO NOTHING'; |
| 115 | - } |
|
| 116 | - else |
|
| 121 | + } else |
|
| 117 | 122 | { |
| 118 | 123 | // Don't error on multi-insert. |
| 119 | 124 | $db_values['db_error_skip'] = true; |
@@ -121,8 +126,9 @@ discard block |
||
| 121 | 126 | } |
| 122 | 127 | |
| 123 | 128 | //fix double quotes |
| 124 | - if ($identifier == 'insert_into_log_messages_fulltext') |
|
| 125 | - $db_values = str_replace('"', "'", $db_values); |
|
| 129 | + if ($identifier == 'insert_into_log_messages_fulltext') { |
|
| 130 | + $db_values = str_replace('"', "'", $db_values); |
|
| 131 | + } |
|
| 126 | 132 | |
| 127 | 133 | $return = $smcFunc['db_query']('', $db_string, |
| 128 | 134 | $db_values, $connection |
@@ -164,9 +170,9 @@ discard block |
||
| 164 | 170 | |
| 165 | 171 | $language_ftx = 'english'; |
| 166 | 172 | |
| 167 | - if (!empty($modSettings['search_language'])) |
|
| 168 | - $language_ftx = $modSettings['search_language']; |
|
| 169 | - else |
|
| 173 | + if (!empty($modSettings['search_language'])) { |
|
| 174 | + $language_ftx = $modSettings['search_language']; |
|
| 175 | + } else |
|
| 170 | 176 | { |
| 171 | 177 | $request = $smcFunc['db_query']('',' |
| 172 | 178 | SHOW default_text_search_config', |