phpBB

Code Changes

File: phpbb/search/fulltext_native.php

  Unmodified   Added   Modified   Removed
Line 285Line 285
		);

$keywords = preg_replace($match, $replace, $keywords);

		);

$keywords = preg_replace($match, $replace, $keywords);

		$num_keywords = sizeof(explode(' ', $keywords));

		$num_keywords = count(explode(' ', $keywords));


// We limit the number of allowed keywords to minimize load on the database
if ($this->config['max_num_search_keywords'] && $num_keywords > $this->config['max_num_search_keywords'])


// We limit the number of allowed keywords to minimize load on the database
if ($this->config['max_num_search_keywords'] && $num_keywords > $this->config['max_num_search_keywords'])

Line 301Line 301
			$words = array();

preg_match_all('#([^\\s+\\-|()]+)(?:$|[\\s+\\-|()])#u', $keywords, $words);

			$words = array();

preg_match_all('#([^\\s+\\-|()]+)(?:$|[\\s+\\-|()])#u', $keywords, $words);

			if (sizeof($words[1]))

			if (count($words[1]))

			{
$keywords = '(' . implode('|', $words[1]) . ')';
}

			{
$keywords = '(' . implode('|', $words[1]) . ')';
}

Line 316Line 316

$common_ids = $words = array();



$common_ids = $words = array();


		if (sizeof($exact_words))

		if (count($exact_words))

		{
$sql = 'SELECT word_id, word_text, word_common
FROM ' . SEARCH_WORDLIST_TABLE . '

		{
$sql = 'SELECT word_id, word_text, word_common
FROM ' . SEARCH_WORDLIST_TABLE . '

Line 426Line 426
						}
}
}

						}
}
}

				if (sizeof($id_words))

				if (count($id_words))

				{
sort($id_words);

				{
sort($id_words);

					if (sizeof($id_words) > 1)

					if (count($id_words) > 1)

					{
$this->{$mode . '_ids'}[] = $id_words;
}

					{
$this->{$mode . '_ids'}[] = $id_words;
}

Line 440Line 440
					}
}
// throw an error if we shall not ignore unexistant words

					}
}
// throw an error if we shall not ignore unexistant words

				else if (!$ignore_no_id && sizeof($non_common_words))

				else if (!$ignore_no_id && count($non_common_words))

				{
trigger_error(sprintf($this->user->lang['WORDS_IN_NO_POST'], implode($this->user->lang['COMMA_SEPARATOR'], $non_common_words)));
}

				{
trigger_error(sprintf($this->user->lang['WORDS_IN_NO_POST'], implode($this->user->lang['COMMA_SEPARATOR'], $non_common_words)));
}

Line 480Line 480
		}

// Return true if all words are not common words

		}

// Return true if all words are not common words

		if (sizeof($exact_words) - sizeof($this->common_words) > 0)

		if (count($exact_words) - count($this->common_words) > 0)

		{
return true;
}

		{
return true;
}

Line 716Line 716
			}
}


			}
}


		if (sizeof($this->must_not_contain_ids))

		if (count($this->must_not_contain_ids))

		{
$sql_array['LEFT_JOIN'][] = array(
'FROM' => array(SEARCH_WORDMATCH_TABLE => 'm' . $m_num),

		{
$sql_array['LEFT_JOIN'][] = array(
'FROM' => array(SEARCH_WORDMATCH_TABLE => 'm' . $m_num),

Line 826Line 826
			$sql_where[] = 'p.topic_id = ' . $topic_id;
}


			$sql_where[] = 'p.topic_id = ' . $topic_id;
}


		if (sizeof($author_ary))

		if (count($author_ary))

		{
if ($author_name)
{

		{
if ($author_name)
{

Line 840Line 840
			$sql_where[] = $sql_author;
}


			$sql_where[] = $sql_author;
}


		if (sizeof($ex_fid_ary))

		if (count($ex_fid_ary))

		{
$sql_where[] = $this->db->sql_in_set('p.forum_id', $ex_fid_ary, true);
}

		{
$sql_where[] = $this->db->sql_in_set('p.forum_id', $ex_fid_ary, true);
}

Line 1010Line 1010
	public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $post_visibility, $topic_id, $author_ary, $author_name, &$id_ary, &$start, $per_page)
{
// No author? No posts

	public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $post_visibility, $topic_id, $author_ary, $author_name, &$id_ary, &$start, $per_page)
{
// No author? No posts

		if (!sizeof($author_ary))

		if (!count($author_ary))

		{
return 0;
}

		{
return 0;
}

Line 1082Line 1082
		{
$sql_author = $this->db->sql_in_set('p.poster_id', $author_ary);
}

		{
$sql_author = $this->db->sql_in_set('p.poster_id', $author_ary);
}

		$sql_fora		= (sizeof($ex_fid_ary)) ? ' AND ' . $this->db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '';

		$sql_fora		= (count($ex_fid_ary)) ? ' AND ' . $this->db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '';

		$sql_time		= ($sort_days) ? ' AND p.post_time >= ' . (time() - ($sort_days * 86400)) : '';
$sql_topic_id = ($topic_id) ? ' AND p.topic_id = ' . (int) $topic_id : '';
$sql_firstpost = ($firstpost_only) ? ' AND p.post_id = t.topic_first_post_id' : '';

		$sql_time		= ($sort_days) ? ' AND p.post_time >= ' . (time() - ($sort_days * 86400)) : '';
$sql_topic_id = ($topic_id) ? ' AND p.topic_id = ' . (int) $topic_id : '';
$sql_firstpost = ($firstpost_only) ? ' AND p.post_id = t.topic_first_post_id' : '';

Line 1289Line 1289
			$this->db->sql_freeresult($result);
}


			$this->db->sql_freeresult($result);
}


		if (sizeof($id_ary))

		if (count($id_ary))

		{
$this->save_ids($search_key, '', $author_ary, $total_results, $id_ary, $start, $sort_dir);
$id_ary = array_slice($id_ary, 0, $per_page);

		{
$this->save_ids($search_key, '', $author_ary, $total_results, $id_ary, $start, $sort_dir);
$id_ary = array_slice($id_ary, 0, $per_page);

Line 1433Line 1433
			$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 1443Line 1475
		// individual arrays of added and removed words for text and title. What
// we need to do now is add the new words (if they don't already exist)
// and then add (or remove) matches between the words and this post

		// individual arrays of added and removed words for text and title. What
// we need to do now is add the new words (if they don't already exist)
// and then add (or remove) matches between the words and this post

		if (sizeof($unique_add_words))

		if (count($unique_add_words))

		{
$sql = 'SELECT word_id, word_text
FROM ' . SEARCH_WORDLIST_TABLE . '

		{
$sql = 'SELECT word_id, word_text
FROM ' . SEARCH_WORDLIST_TABLE . '

Line 1459Line 1491
			$new_words = array_diff($unique_add_words, array_keys($word_ids));

$this->db->sql_transaction('begin');

			$new_words = array_diff($unique_add_words, array_keys($word_ids));

$this->db->sql_transaction('begin');

			if (sizeof($new_words))

			if (count($new_words))

			{
$sql_ary = array();


			{
$sql_ary = array();


Line 1483Line 1515
		{
$title_match = ($word_in == 'title') ? 1 : 0;


		{
$title_match = ($word_in == 'title') ? 1 : 0;


			if (sizeof($word_ary))

			if (count($word_ary))

			{
$sql_in = array();
foreach ($word_ary as $word)

			{
$sql_in = array();
foreach ($word_ary as $word)

Line 1512Line 1544
		{
$title_match = ($word_in == 'title') ? 1 : 0;


		{
$title_match = ($word_in == 'title') ? 1 : 0;


			if (sizeof($word_ary))

			if (count($word_ary))

			{
$sql = 'INSERT INTO ' . SEARCH_WORDMATCH_TABLE . ' (post_id, word_id, title_match)
SELECT ' . (int) $post_id . ', word_id, ' . (int) $title_match . '

			{
$sql = 'INSERT INTO ' . SEARCH_WORDMATCH_TABLE . ' (post_id, word_id, title_match)
SELECT ' . (int) $post_id . ', word_id, ' . (int) $title_match . '

Line 1543Line 1575
	*/
public function index_remove($post_ids, $author_ids, $forum_ids)
{

	*/
public function index_remove($post_ids, $author_ids, $forum_ids)
{

		if (sizeof($post_ids))

		if (count($post_ids))

		{
$sql = 'SELECT w.word_id, w.word_text, m.title_match
FROM ' . SEARCH_WORDMATCH_TABLE . ' m, ' . SEARCH_WORDLIST_TABLE . ' w

		{
$sql = 'SELECT w.word_id, w.word_text, m.title_match
FROM ' . SEARCH_WORDMATCH_TABLE . ' m, ' . SEARCH_WORDLIST_TABLE . ' w

Line 1566Line 1598
			}
$this->db->sql_freeresult($result);


			}
$this->db->sql_freeresult($result);


			if (sizeof($title_word_ids))

			if (count($title_word_ids))

			{
$sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . '
SET word_count = word_count - 1

			{
$sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . '
SET word_count = word_count - 1

Line 1575Line 1607
				$this->db->sql_query($sql);
}


				$this->db->sql_query($sql);
}


			if (sizeof($message_word_ids))

			if (count($message_word_ids))

			{
$sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . '
SET word_count = word_count - 1

			{
$sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . '
SET word_count = word_count - 1

Line 1630Line 1662
			}
$this->db->sql_freeresult($result);


			}
$this->db->sql_freeresult($result);


			if (sizeof($sql_in))

			if (count($sql_in))

			{
// Flag the words
$sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . '

			{
// Flag the words
$sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . '

Line 1650Line 1682
			unset($sql_in);
}


			unset($sql_in);
}


		if (sizeof($destroy_cache_words))

		if (count($destroy_cache_words))

		{
// destroy cached search results containing any of the words that are now common or were removed
$this->destroy_cache(array_unique($destroy_cache_words));

		{
// destroy cached search results containing any of the words that are now common or were removed
$this->destroy_cache(array_unique($destroy_cache_words));

Line 1664Line 1696
	*/
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);

		}
}


		}
}


Line 1685Line 1740
	*/
public function index_created()
{

	*/
public function index_created()
{

		if (!sizeof($this->stats))

		if (!count($this->stats))

		{
$this->get_stats();
}

		{
$this->get_stats();
}

Line 1698Line 1753
	*/
public function index_stats()
{

	*/
public function index_stats()
{

		if (!sizeof($this->stats))

		if (!count($this->stats))

		{
$this->get_stats();
}

		{
$this->get_stats();
}