phpBB

Code Changes

File: phpbb/search/fulltext_native.php

  Unmodified   Added   Modified   Removed
Line 190Line 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 224Line 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 264Line 262
			}
}


			}
}


		if ($open_bracket)

		if ($open_bracket !== false)

		{
$keywords .= ')';
}

		{
$keywords .= ')';
}

Line 306Line 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 408Line 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]))
{

Line 1433Line 1453
			$words['del']['post'] = array();
$words['del']['title'] = array();
}

			$words['del']['post'] = array();
$words['del']['title'] = array();
}

 

/**
* Event to modify method arguments and words before the native search index is updated
*
* @event core.search_native_index_before
* @var string mode Contains the post mode: edit, post, reply, quote
* @var int post_id The id of the post which is modified/created
* @var string message New or updated post content
* @var string subject New or updated post subject
* @var int poster_id Post author's user id
* @var int forum_id The id of the forum in which the post is located
* @var array words Grouped lists of words added to or remove from the index
* @var array split_text Array of words from the message
* @var array split_title Array of words from the title
* @var array cur_words Array of words currently in the index for comparing to new words
* when mode is edit. Empty for other modes.
* @since 3.2.3-RC1
*/
$vars = array(
'mode',
'post_id',
'message',
'subject',
'poster_id',
'forum_id',
'words',
'split_text',
'split_title',
'cur_words',
);
extract($this->phpbb_dispatcher->trigger_event('core.search_native_index_before', compact($vars)));


		unset($split_text);
unset($split_title);


		unset($split_text);
unset($split_title);


Line 1664Line 1716
	*/
public function delete_index($acp_module, $u_action)
{

	*/
public function delete_index($acp_module, $u_action)
{

 
		$sql_queries = [];


		switch ($this->db->get_sql_layer())
{
case 'sqlite3':

		switch ($this->db->get_sql_layer())
{
case 'sqlite3':

				$this->db->sql_query('DELETE FROM ' . SEARCH_WORDLIST_TABLE);
$this->db->sql_query('DELETE FROM ' . SEARCH_WORDMATCH_TABLE);
$this->db->sql_query('DELETE FROM ' . SEARCH_RESULTS_TABLE);

				$sql_queries[] = 'DELETE FROM ' . SEARCH_WORDLIST_TABLE;
$sql_queries[] = 'DELETE FROM ' . SEARCH_WORDMATCH_TABLE;
$sql_queries[] = 'DELETE FROM ' . SEARCH_RESULTS_TABLE;

			break;

default:

			break;

default:

				$this->db->sql_query('TRUNCATE TABLE ' . SEARCH_WORDLIST_TABLE);
$this->db->sql_query('TRUNCATE TABLE ' . SEARCH_WORDMATCH_TABLE);
$this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE);

				$sql_queries[] = 'TRUNCATE TABLE ' . SEARCH_WORDLIST_TABLE;
$sql_queries[] = 'TRUNCATE TABLE ' . SEARCH_WORDMATCH_TABLE;
$sql_queries[] = 'TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE;

			break;

			break;

 
		}

$stats = $this->stats;

/**
* Event to modify SQL queries before the native search index is deleted
*
* @event core.search_native_delete_index_before
* @var array sql_queries Array with queries for deleting the search index
* @var array stats Array with statistics of the current index (read only)
* @since 3.2.3-RC1
*/
$vars = array(
'sql_queries',
'stats',
);
extract($this->phpbb_dispatcher->trigger_event('core.search_native_delete_index_before', compact($vars)));

foreach ($sql_queries as $sql_query)
{
$this->db->sql_query($sql_query);

		}
}


		}
}