| Conditions | 41 |
| Paths | 8192 |
| Total Lines | 114 |
| Code Lines | 71 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 168 | public function indexedWordQuery(array $words, array $search_data) |
||
| 169 | { |
||
| 170 | global $modSettings, $smcFunc; |
||
| 171 | |||
| 172 | $query_select = array( |
||
| 173 | 'id_msg' => 'm.id_msg', |
||
| 174 | ); |
||
| 175 | $query_where = array(); |
||
| 176 | $query_params = $search_data['params']; |
||
| 177 | |||
| 178 | if ($smcFunc['db_title'] == "PostgreSQL") |
||
| 179 | $modSettings['search_simple_fulltext'] = true; |
||
| 180 | |||
| 181 | if ($query_params['id_search']) |
||
| 182 | $query_select['id_search'] = '{int:id_search}'; |
||
| 183 | |||
| 184 | $count = 0; |
||
| 185 | if (empty($modSettings['search_simple_fulltext'])) |
||
| 186 | foreach ($words['words'] as $regularWord) |
||
| 187 | { |
||
| 188 | $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 . '}'; |
||
| 189 | $query_params['complex_body_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($regularWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $regularWord), '\\\'') . '[[:>:]]'; |
||
| 190 | } |
||
| 191 | |||
| 192 | if ($query_params['user_query']) |
||
| 193 | $query_where[] = '{raw:user_query}'; |
||
| 194 | if ($query_params['board_query']) |
||
| 195 | $query_where[] = 'm.id_board {raw:board_query}'; |
||
| 196 | |||
| 197 | if ($query_params['topic']) |
||
| 198 | $query_where[] = 'm.id_topic = {int:topic}'; |
||
| 199 | if ($query_params['min_msg_id']) |
||
| 200 | $query_where[] = 'm.id_msg >= {int:min_msg_id}'; |
||
| 201 | if ($query_params['max_msg_id']) |
||
| 202 | $query_where[] = 'm.id_msg <= {int:max_msg_id}'; |
||
| 203 | |||
| 204 | $count = 0; |
||
| 205 | if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) |
||
| 206 | foreach ($query_params['excluded_phrases'] as $phrase) |
||
| 207 | { |
||
| 208 | $query_where[] = 'subject NOT' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : ' RLIKE ') . '{string:exclude_subject_phrase_' . $count . '}'; |
||
| 209 | $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), '\\\'') . '[[:>:]]'; |
||
| 210 | } |
||
| 211 | $count = 0; |
||
| 212 | if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) |
||
| 213 | foreach ($query_params['excluded_subject_words'] as $excludedWord) |
||
| 214 | { |
||
| 215 | $query_where[] = 'subject NOT' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : ' RLIKE ') . '{string:exclude_subject_words_' . $count . '}'; |
||
| 216 | $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), '\\\'') . '[[:>:]]'; |
||
| 217 | } |
||
| 218 | |||
| 219 | if (!empty($modSettings['search_simple_fulltext'])) |
||
| 220 | { |
||
| 221 | if ($smcFunc['db_title'] == "PostgreSQL") |
||
| 222 | { |
||
| 223 | $language_ftx = $smcFunc['db_search_language'](); |
||
| 224 | |||
| 225 | $query_where[] = 'to_tsvector({string:language_ftx},body) @@ plainto_tsquery({string:language_ftx},{string:body_match})'; |
||
| 226 | $query_params['language_ftx'] = $language_ftx; |
||
| 227 | } |
||
| 228 | else |
||
| 229 | $query_where[] = 'MATCH (body) AGAINST ({string:body_match})'; |
||
| 230 | $query_params['body_match'] = implode(' ', array_diff($words['indexed_words'], $query_params['excluded_index_words'])); |
||
| 231 | } |
||
| 232 | else |
||
| 233 | { |
||
| 234 | $query_params['boolean_match'] = ''; |
||
| 235 | |||
| 236 | // remove any indexed words that are used in the complex body search terms |
||
| 237 | $words['indexed_words'] = array_diff($words['indexed_words'], $words['complex_words']); |
||
| 238 | |||
| 239 | if ($smcFunc['db_title'] == "PostgreSQL") |
||
| 240 | { |
||
| 241 | $row = 0; |
||
| 242 | foreach ($words['indexed_words'] as $fulltextWord) |
||
| 243 | { |
||
| 244 | $query_params['boolean_match'] .= ($row <> 0 ? '&' : ''); |
||
| 245 | $query_params['boolean_match'] .= (in_array($fulltextWord, $query_params['excluded_index_words']) ? '!' : '') . $fulltextWord . ' '; |
||
| 246 | $row++; |
||
| 247 | } |
||
| 248 | } |
||
| 249 | else |
||
| 250 | foreach ($words['indexed_words'] as $fulltextWord) |
||
| 251 | $query_params['boolean_match'] .= (in_array($fulltextWord, $query_params['excluded_index_words']) ? '-' : '+') . $fulltextWord . ' '; |
||
| 252 | |||
| 253 | $query_params['boolean_match'] = substr($query_params['boolean_match'], 0, -1); |
||
| 254 | |||
| 255 | // if we have bool terms to search, add them in |
||
| 256 | if ($query_params['boolean_match']) |
||
| 257 | { |
||
| 258 | if ($smcFunc['db_title'] == "PostgreSQL") |
||
| 259 | { |
||
| 260 | $language_ftx = $smcFunc['db_search_language'](); |
||
| 261 | |||
| 262 | $query_where[] = 'to_tsvector({string:language_ftx},body) @@ plainto_tsquery({string:language_ftx},{string:boolean_match})'; |
||
| 263 | $query_params['language_ftx'] = $language_ftx; |
||
| 264 | } |
||
| 265 | else |
||
| 266 | $query_where[] = 'MATCH (body) AGAINST ({string:boolean_match} IN BOOLEAN MODE)'; |
||
| 267 | } |
||
| 268 | } |
||
| 269 | |||
| 270 | $ignoreRequest = $smcFunc['db_search_query']('insert_into_log_messages_fulltext', ($smcFunc['db_support_ignore'] ? (' |
||
| 271 | INSERT IGNORE INTO {db_prefix}' . $search_data['insert_into'] . ' |
||
| 272 | (' . implode(', ', array_keys($query_select)) . ')') : '') . ' |
||
| 273 | SELECT ' . implode(', ', $query_select) . ' |
||
| 274 | FROM {db_prefix}messages AS m |
||
| 275 | WHERE ' . implode(' |
||
| 276 | AND ', $query_where) . (empty($search_data['max_results']) ? '' : ' |
||
| 277 | LIMIT ' . ($search_data['max_results'] - $search_data['indexed_results'])), |
||
| 278 | $query_params |
||
| 279 | ); |
||
| 280 | |||
| 281 | return $ignoreRequest; |
||
| 282 | } |
||
| 285 | ?> |