| Conditions | 34 |
| Paths | > 20000 |
| Total Lines | 83 |
| Code Lines | 58 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 150 | public function indexedWordQuery(array $words, array $search_data) |
||
| 151 | { |
||
| 152 | global $modSettings, $smcFunc; |
||
| 153 | |||
| 154 | $query_select = array( |
||
| 155 | 'id_msg' => 'm.id_msg', |
||
| 156 | ); |
||
| 157 | $query_inner_join = array(); |
||
| 158 | $query_left_join = array(); |
||
| 159 | $query_where = array(); |
||
| 160 | $query_params = $search_data['params']; |
||
| 161 | |||
| 162 | if ($query_params['id_search']) |
||
| 163 | $query_select['id_search'] = '{int:id_search}'; |
||
| 164 | |||
| 165 | $count = 0; |
||
| 166 | foreach ($words['words'] as $regularWord) |
||
| 167 | { |
||
| 168 | $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 . '}'; |
||
| 169 | $query_params['complex_body_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($regularWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $regularWord), '\\\'') . '[[:>:]]'; |
||
| 170 | } |
||
| 171 | |||
| 172 | if ($query_params['user_query']) |
||
| 173 | $query_where[] = '{raw:user_query}'; |
||
| 174 | if ($query_params['board_query']) |
||
| 175 | $query_where[] = 'm.id_board {raw:board_query}'; |
||
| 176 | |||
| 177 | if ($query_params['topic']) |
||
| 178 | $query_where[] = 'm.id_topic = {int:topic}'; |
||
| 179 | if ($query_params['min_msg_id']) |
||
| 180 | $query_where[] = 'm.id_msg >= {int:min_msg_id}'; |
||
| 181 | if ($query_params['max_msg_id']) |
||
| 182 | $query_where[] = 'm.id_msg <= {int:max_msg_id}'; |
||
| 183 | |||
| 184 | $count = 0; |
||
| 185 | if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) |
||
| 186 | foreach ($query_params['excluded_phrases'] as $phrase) |
||
| 187 | { |
||
| 188 | $query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : ' RLIKE ') . '{string:exclude_subject_phrase_' . $count . '}'; |
||
| 189 | $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), '\\\'') . '[[:>:]]'; |
||
| 190 | } |
||
| 191 | $count = 0; |
||
| 192 | if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) |
||
| 193 | foreach ($query_params['excluded_subject_words'] as $excludedWord) |
||
| 194 | { |
||
| 195 | $query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : ' RLIKE ') . '{string:exclude_subject_words_' . $count . '}'; |
||
| 196 | $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), '\\\'') . '[[:>:]]'; |
||
| 197 | } |
||
| 198 | |||
| 199 | $numTables = 0; |
||
| 200 | $prev_join = 0; |
||
| 201 | foreach ($words['indexed_words'] as $indexedWord) |
||
| 202 | { |
||
| 203 | $numTables++; |
||
| 204 | if (in_array($indexedWord, $query_params['excluded_index_words'])) |
||
| 205 | { |
||
| 206 | $query_left_join[] = '{db_prefix}log_search_words AS lsw' . $numTables . ' ON (lsw' . $numTables . '.id_word = ' . $indexedWord . ' AND lsw' . $numTables . '.id_msg = m.id_msg)'; |
||
| 207 | $query_where[] = '(lsw' . $numTables . '.id_word IS NULL)'; |
||
| 208 | } |
||
| 209 | else |
||
| 210 | { |
||
| 211 | $query_inner_join[] = '{db_prefix}log_search_words AS lsw' . $numTables . ' ON (lsw' . $numTables . '.id_msg = ' . ($prev_join === 0 ? 'm' : 'lsw' . $prev_join) . '.id_msg)'; |
||
| 212 | $query_where[] = 'lsw' . $numTables . '.id_word = ' . $indexedWord; |
||
| 213 | $prev_join = $numTables; |
||
| 214 | } |
||
| 215 | } |
||
| 216 | |||
| 217 | $ignoreRequest = $smcFunc['db_search_query']('insert_into_log_messages_fulltext', ($smcFunc['db_support_ignore'] ? (' |
||
| 218 | INSERT IGNORE INTO {db_prefix}' . $search_data['insert_into'] . ' |
||
| 219 | (' . implode(', ', array_keys($query_select)) . ')') : '') . ' |
||
| 220 | SELECT ' . implode(', ', $query_select) . ' |
||
| 221 | FROM {db_prefix}messages AS m' . (empty($query_inner_join) ? '' : ' |
||
| 222 | INNER JOIN ' . implode(' |
||
| 223 | INNER JOIN ', $query_inner_join)) . (empty($query_left_join) ? '' : ' |
||
| 224 | LEFT JOIN ' . implode(' |
||
| 225 | LEFT JOIN ', $query_left_join)) . ' |
||
| 226 | WHERE ' . implode(' |
||
| 227 | AND ', $query_where) . (empty($search_data['max_results']) ? '' : ' |
||
| 228 | LIMIT ' . ($search_data['max_results'] - $search_data['indexed_results'])), |
||
| 229 | $query_params |
||
| 230 | ); |
||
| 231 | |||
| 232 | return $ignoreRequest; |
||
| 233 | } |
||
| 310 | ?> |