phpBB

Code Changes

File: phpbb/search/fulltext_mysql.php

  Unmodified   Added   Modified   Removed
Line 232Line 232
		$this->split_words = $matches[1];

// We limit the number of allowed keywords to minimize load on the database

		$this->split_words = $matches[1];

// We limit the number of allowed keywords to minimize load on the database

		if ($this->config['max_num_search_keywords'] && sizeof($this->split_words) > $this->config['max_num_search_keywords'])

		if ($this->config['max_num_search_keywords'] && count($this->split_words) > $this->config['max_num_search_keywords'])

		{

		{

			trigger_error($this->user->lang('MAX_NUM_SEARCH_KEYWORDS_REFINE', (int) $this->config['max_num_search_keywords'], sizeof($this->split_words)));

			trigger_error($this->user->lang('MAX_NUM_SEARCH_KEYWORDS_REFINE', (int) $this->config['max_num_search_keywords'], count($this->split_words)));

		}

// to allow phrase search, we need to concatenate quoted words

		}

// to allow phrase search, we need to concatenate quoted words

Line 361Line 361

// remove too short or too long words
$text = array_values($text);


// remove too short or too long words
$text = array_values($text);

		for ($i = 0, $n = sizeof($text); $i < $n; $i++)

		for ($i = 0, $n = count($text); $i < $n; $i++)

		{
$text[$i] = trim($text[$i]);
if (utf8_strlen($text[$i]) < $this->config['fulltext_mysql_min_word_len'] || utf8_strlen($text[$i]) > $this->config['fulltext_mysql_max_word_len'])

		{
$text[$i] = trim($text[$i]);
if (utf8_strlen($text[$i]) < $this->config['fulltext_mysql_min_word_len'] || utf8_strlen($text[$i]) > $this->config['fulltext_mysql_max_word_len'])

Line 563Line 563
		$sql_select			= ($type == 'posts') ? $sql_select . 'p.post_id' : 'DISTINCT ' . $sql_select . 't.topic_id';
$sql_from = ($join_topic) ? TOPICS_TABLE . ' t, ' : '';
$field = ($type == 'posts') ? 'post_id' : 'topic_id';

		$sql_select			= ($type == 'posts') ? $sql_select . 'p.post_id' : 'DISTINCT ' . $sql_select . 't.topic_id';
$sql_from = ($join_topic) ? TOPICS_TABLE . ' t, ' : '';
$field = ($type == 'posts') ? 'post_id' : 'topic_id';

		if (sizeof($author_ary) && $author_name)

		if (count($author_ary) && $author_name)

		{
// first one matches post of registered users, second one guests and deleted users
$sql_author = ' AND (' . $this->db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')';
}

		{
// first one matches post of registered users, second one guests and deleted users
$sql_author = ' AND (' . $this->db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')';
}

		else if (sizeof($author_ary))

		else if (count($author_ary))

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

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

Line 580Line 580
		$sql_where_options = $sql_sort_join;
$sql_where_options .= ($topic_id) ? ' AND p.topic_id = ' . $topic_id : '';
$sql_where_options .= ($join_topic) ? ' AND t.topic_id = p.topic_id' : '';

		$sql_where_options = $sql_sort_join;
$sql_where_options .= ($topic_id) ? ' AND p.topic_id = ' . $topic_id : '';
$sql_where_options .= ($join_topic) ? ' AND t.topic_id = p.topic_id' : '';

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

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

		$sql_where_options .= ' AND ' . $post_visibility;
$sql_where_options .= $sql_author;
$sql_where_options .= ($sort_days) ? ' AND p.post_time >= ' . (time() - ($sort_days * 86400)) : '';

		$sql_where_options .= ' AND ' . $post_visibility;
$sql_where_options .= $sql_author;
$sql_where_options .= ($sort_days) ? ' AND p.post_time >= ' . (time() - ($sort_days * 86400)) : '';

Line 591Line 591
			WHERE MATCH ($sql_match) AGAINST ('" . $this->db->sql_escape(htmlspecialchars_decode($this->search_query)) . "' IN BOOLEAN MODE)
$sql_where_options
ORDER BY $sql_sort";

			WHERE MATCH ($sql_match) AGAINST ('" . $this->db->sql_escape(htmlspecialchars_decode($this->search_query)) . "' IN BOOLEAN MODE)
$sql_where_options
ORDER BY $sql_sort";

 
		$this->db->sql_return_on_error(true);

		$result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start);

while ($row = $this->db->sql_fetchrow($result))

		$result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start);

while ($row = $this->db->sql_fetchrow($result))

Line 602Line 603
		$id_ary = array_unique($id_ary);

// if the total result count is not cached yet, retrieve it from the db

		$id_ary = array_unique($id_ary);

// if the total result count is not cached yet, retrieve it from the db

		if (!$result_count)

		if (!$result_count && count($id_ary))

		{
$sql_found_rows = 'SELECT FOUND_ROWS() as result_count';
$result = $this->db->sql_query($sql_found_rows);

		{
$sql_found_rows = 'SELECT FOUND_ROWS() as result_count';
$result = $this->db->sql_query($sql_found_rows);

Line 659Line 660
	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 736Line 737
		{
$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_topic_id	= ($topic_id) ? ' AND p.topic_id = ' . (int) $topic_id : '';
$sql_time = ($sort_days) ? ' AND p.post_time >= ' . (time() - ($sort_days * 86400)) : '';
$sql_firstpost = ($firstpost_only) ? ' AND p.post_id = t.topic_first_post_id' : '';

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

Line 889Line 890
			$id_ary = array_unique($id_ary);
}


			$id_ary = array_unique($id_ary);
}


		if (sizeof($id_ary))

		if (count($id_ary))

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

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

Line 996Line 997
			$alter_list[] = $alter_entry;
}


			$alter_list[] = $alter_entry;
}


		if (sizeof($alter_list))

		if (count($alter_list))

		{
foreach ($alter_list as $alter)
{
$this->db->sql_query('ALTER TABLE ' . POSTS_TABLE . ' ' . implode(', ', $alter));
}

		{
foreach ($alter_list as $alter)
{
$this->db->sql_query('ALTER TABLE ' . POSTS_TABLE . ' ' . implode(', ', $alter));
}

 
		}

if (!isset($this->stats['post_text']))
{
$this->db->sql_query('ALTER TABLE ' . POSTS_TABLE . ' ADD FULLTEXT post_text (post_text)');

		}

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

		}

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

Line 1039Line 1045
			$alter[] = 'DROP INDEX post_content';
}


			$alter[] = 'DROP INDEX post_content';
}


		if (sizeof($alter))






		if (isset($this->stats['post_text']))
{
$alter[] = 'DROP INDEX post_text';
}

if (count($alter))

		{
$this->db->sql_query('ALTER TABLE ' . POSTS_TABLE . ' ' . implode(', ', $alter));
}

		{
$this->db->sql_query('ALTER TABLE ' . POSTS_TABLE . ' ' . implode(', ', $alter));
}

Line 1059Line 1070
			$this->get_stats();
}


			$this->get_stats();
}


		return isset($this->stats['post_subject']) && isset($this->stats['post_content']);

		return isset($this->stats['post_subject']) && isset($this->stats['post_content']) && isset($this->stats['post_text']);

	}

/**

	}

/**

Line 1102Line 1113
				if ($row['Key_name'] == 'post_subject')
{
$this->stats['post_subject'] = $row;

				if ($row['Key_name'] == 'post_subject')
{
$this->stats['post_subject'] = $row;

 
				}
else if ($row['Key_name'] == 'post_text')
{
$this->stats['post_text'] = $row;

				}
else if ($row['Key_name'] == 'post_content')
{

				}
else if ($row['Key_name'] == 'post_content')
{