@@ -11,8 +11,9 @@ discard block |
||
| 11 | 11 | * @version 2.1 Beta 4 |
| 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,44 +168,54 @@ discard block |
||
| 166 | 168 | $query_where = array(); |
| 167 | 169 | $query_params = $search_data['params']; |
| 168 | 170 | |
| 169 | - if( $smcFunc['db_title'] == "PostgreSQL") |
|
| 170 | - $modSettings['search_simple_fulltext'] = true; |
|
| 171 | + if( $smcFunc['db_title'] == "PostgreSQL") { |
|
| 172 | + $modSettings['search_simple_fulltext'] = true; |
|
| 173 | + } |
|
| 171 | 174 | |
| 172 | - if ($query_params['id_search']) |
|
| 173 | - $query_select['id_search'] = '{int:id_search}'; |
|
| 175 | + if ($query_params['id_search']) { |
|
| 176 | + $query_select['id_search'] = '{int:id_search}'; |
|
| 177 | + } |
|
| 174 | 178 | |
| 175 | 179 | $count = 0; |
| 176 | - if (empty($modSettings['search_simple_fulltext'])) |
|
| 177 | - foreach ($words['words'] as $regularWord) |
|
| 180 | + if (empty($modSettings['search_simple_fulltext'])) { |
|
| 181 | + foreach ($words['words'] as $regularWord) |
|
| 178 | 182 | { |
| 179 | 183 | $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 . '}'; |
| 184 | + } |
|
| 180 | 185 | $query_params['complex_body_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($regularWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $regularWord), '\\\'') . '[[:>:]]'; |
| 181 | 186 | } |
| 182 | 187 | |
| 183 | - if ($query_params['user_query']) |
|
| 184 | - $query_where[] = '{raw:user_query}'; |
|
| 185 | - if ($query_params['board_query']) |
|
| 186 | - $query_where[] = 'm.id_board {raw:board_query}'; |
|
| 188 | + if ($query_params['user_query']) { |
|
| 189 | + $query_where[] = '{raw:user_query}'; |
|
| 190 | + } |
|
| 191 | + if ($query_params['board_query']) { |
|
| 192 | + $query_where[] = 'm.id_board {raw:board_query}'; |
|
| 193 | + } |
|
| 187 | 194 | |
| 188 | - if ($query_params['topic']) |
|
| 189 | - $query_where[] = 'm.id_topic = {int:topic}'; |
|
| 190 | - if ($query_params['min_msg_id']) |
|
| 191 | - $query_where[] = 'm.id_msg >= {int:min_msg_id}'; |
|
| 192 | - if ($query_params['max_msg_id']) |
|
| 193 | - $query_where[] = 'm.id_msg <= {int:max_msg_id}'; |
|
| 195 | + if ($query_params['topic']) { |
|
| 196 | + $query_where[] = 'm.id_topic = {int:topic}'; |
|
| 197 | + } |
|
| 198 | + if ($query_params['min_msg_id']) { |
|
| 199 | + $query_where[] = 'm.id_msg >= {int:min_msg_id}'; |
|
| 200 | + } |
|
| 201 | + if ($query_params['max_msg_id']) { |
|
| 202 | + $query_where[] = 'm.id_msg <= {int:max_msg_id}'; |
|
| 203 | + } |
|
| 194 | 204 | |
| 195 | 205 | $count = 0; |
| 196 | - if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) |
|
| 197 | - foreach ($query_params['excluded_phrases'] as $phrase) |
|
| 206 | + if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) { |
|
| 207 | + foreach ($query_params['excluded_phrases'] as $phrase) |
|
| 198 | 208 | { |
| 199 | 209 | $query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:exclude_subject_phrase_' . $count . '}'; |
| 210 | + } |
|
| 200 | 211 | $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), '\\\'') . '[[:>:]]'; |
| 201 | 212 | } |
| 202 | 213 | $count = 0; |
| 203 | - if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) |
|
| 204 | - foreach ($query_params['excluded_subject_words'] as $excludedWord) |
|
| 214 | + if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) { |
|
| 215 | + foreach ($query_params['excluded_subject_words'] as $excludedWord) |
|
| 205 | 216 | { |
| 206 | 217 | $query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:exclude_subject_words_' . $count . '}'; |
| 218 | + } |
|
| 207 | 219 | $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), '\\\'') . '[[:>:]]'; |
| 208 | 220 | } |
| 209 | 221 | |
@@ -215,12 +227,11 @@ discard block |
||
| 215 | 227 | |
| 216 | 228 | $query_where[] = 'to_tsvector({string:language_ftx},body) @@ plainto_tsquery({string:language_ftx},{string:body_match})'; |
| 217 | 229 | $query_params['language_ftx'] = $language_ftx; |
| 230 | + } else { |
|
| 231 | + $query_where[] = 'MATCH (body) AGAINST ({string:body_match})'; |
|
| 218 | 232 | } |
| 219 | - else |
|
| 220 | - $query_where[] = 'MATCH (body) AGAINST ({string:body_match})'; |
|
| 221 | 233 | $query_params['body_match'] = implode(' ', array_diff($words['indexed_words'], $query_params['excluded_index_words'])); |
| 222 | - } |
|
| 223 | - else |
|
| 234 | + } else |
|
| 224 | 235 | { |
| 225 | 236 | $query_params['boolean_match'] = ''; |
| 226 | 237 | |
@@ -234,10 +245,10 @@ discard block |
||
| 234 | 245 | $query_params['boolean_match'] .= (in_array($fulltextWord, $query_params['excluded_index_words']) ? '!' : '') . $fulltextWord . ' '; |
| 235 | 246 | $row++; |
| 236 | 247 | } |
| 237 | - } |
|
| 238 | - else |
|
| 239 | - foreach ($words['indexed_words'] as $fulltextWord) |
|
| 248 | + } else { |
|
| 249 | + foreach ($words['indexed_words'] as $fulltextWord) |
|
| 240 | 250 | $query_params['boolean_match'] .= (in_array($fulltextWord, $query_params['excluded_index_words']) ? '-' : '+') . $fulltextWord . ' '; |
| 251 | + } |
|
| 241 | 252 | |
| 242 | 253 | $query_params['boolean_match'] = substr($query_params['boolean_match'], 0, -1); |
| 243 | 254 | |
@@ -249,9 +260,9 @@ discard block |
||
| 249 | 260 | |
| 250 | 261 | $query_where[] = 'to_tsvector({string:language_ftx},body) @@ plainto_tsquery({string:language_ftx},{string:boolean_match})'; |
| 251 | 262 | $query_params['language_ftx'] = $language_ftx; |
| 263 | + } else { |
|
| 264 | + $query_where[] = 'MATCH (body) AGAINST ({string:boolean_match} IN BOOLEAN MODE)'; |
|
| 252 | 265 | } |
| 253 | - else |
|
| 254 | - $query_where[] = 'MATCH (body) AGAINST ({string:boolean_match} IN BOOLEAN MODE)'; |
|
| 255 | 266 | } |
| 256 | 267 | |
| 257 | 268 | } |