Line 190 | Line 190 |
---|
*/ public function split_keywords($keywords, $terms) {
|
*/ public function split_keywords($keywords, $terms) {
|
$tokens = '+-|()*';
| $tokens = '+-|()* ';
|
$keywords = trim($this->cleanup($keywords, $tokens));
| $keywords = trim($this->cleanup($keywords, $tokens));
|
Line 224 | Line 224 |
---|
$keywords[$i] = '|'; break; case '*':
|
$keywords[$i] = '|'; break; case '*':
|
if ($i === 0 || ($keywords[$i - 1] !== '*' && strcspn($keywords[$i - 1], $tokens) === 0))
| // $i can never be 0 here since $open_bracket is initialised to false if (strpos($tokens, $keywords[$i - 1]) !== false && ($i + 1 === $n || strpos($tokens, $keywords[$i + 1]) !== false))
|
{
|
{
|
if ($i === $n - 1 || ($keywords[$i + 1] !== '*' && strcspn($keywords[$i + 1], $tokens) === 0)) { $keywords = substr($keywords, 0, $i) . substr($keywords, $i + 1); }
| $keywords[$i] = '|';
|
} break; }
| } break; }
|
Line 264 | Line 262 |
---|
} }
|
} }
|
if ($open_bracket)
| if ($open_bracket !== false)
|
{ $keywords .= ')'; }
| { $keywords .= ')'; }
|
Line 306 | Line 304 |
---|
$keywords = '(' . implode('|', $words[1]) . ')'; } }
|
$keywords = '(' . implode('|', $words[1]) . ')'; } }
|
| // Remove non trailing wildcards from each word to prevent a full table scan (it's now using the database index) $match = '#\*(?!$|\s)#'; $replace = '$1'; $keywords = preg_replace($match, $replace, $keywords);
// Only allow one wildcard in the search query to limit the database load $match = '#\*#'; $replace = '$1'; $count_wildcards = substr_count($keywords, '*');
// Reverse the string to remove all wildcards except the first one $keywords = strrev(preg_replace($match, $replace, strrev($keywords), $count_wildcards - 1)); unset($count_wildcards);
|
// set the search_query which is shown to the user $this->search_query = $keywords;
| // set the search_query which is shown to the user $this->search_query = $keywords;
|
Line 408 | Line 420 |
---|
foreach ($word as $i => $word_part) { if (strpos($word_part, '*') !== false)
|
foreach ($word as $i => $word_part) { if (strpos($word_part, '*') !== false)
|
| { $len = utf8_strlen(str_replace('*', '', $word_part)); if ($len >= $this->word_length['min'] && $len <= $this->word_length['max'])
|
{ $id_words[] = '\'' . $this->db->sql_escape(str_replace('*', '%', $word_part)) . '\''; $non_common_words[] = $word_part;
|
{ $id_words[] = '\'' . $this->db->sql_escape(str_replace('*', '%', $word_part)) . '\''; $non_common_words[] = $word_part;
|
| } else { $this->common_words[] = $word_part; }
|
} else if (isset($words[$word_part])) {
| } else if (isset($words[$word_part])) {
|