phpBB

Code Changes

File: search.php

  Unmodified   Added   Modified   Removed
Line 468Line 468
	// show_results should not change after this
$per_page = ($show_results == 'posts') ? $config['posts_per_page'] : $config['topics_per_page'];
$total_match_count = 0;

	// show_results should not change after this
$per_page = ($show_results == 'posts') ? $config['posts_per_page'] : $config['topics_per_page'];
$total_match_count = 0;

 

// Set limit for the $total_match_count to reduce server load
$total_matches_limit = 1000;
$found_more_search_matches = false;


if ($search_id)
{
if ($sql)
{


if ($search_id)
{
if ($sql)
{

			// only return up to 1000 ids (the last one will be removed later)
$result = $db->sql_query_limit($sql, 1001 - $start, $start);

			// Only return up to $total_matches_limit+1 ids (the last one will be removed later)
$result = $db->sql_query_limit($sql, $total_matches_limit + 1);


while ($row = $db->sql_fetchrow($result))
{
$id_ary[] = (int) $row[$field];
}
$db->sql_freeresult($result);


while ($row = $db->sql_fetchrow($result))
{
$id_ary[] = (int) $row[$field];
}
$db->sql_freeresult($result);


$total_match_count = sizeof($id_ary) + $start;
$id_ary = array_slice($id_ary, 0, $per_page);

 
		}
else if ($search_id == 'unreadposts')
{

		}
else if ($search_id == 'unreadposts')
{

			$id_ary = array_keys(get_unread_topics($user->data['user_id'], $sql_where, $sql_sort, 1001 - $start, $start));

$total_match_count = sizeof($id_ary) + $start;
$id_ary = array_slice($id_ary, 0, $per_page);

			// Only return up to $total_matches_limit+1 ids (the last one will be removed later)
$id_ary = array_keys(get_unread_topics($user->data['user_id'], $sql_where, $sql_sort, $total_matches_limit + 1));



		}
else
{
$search_id = '';

		}
else
{
$search_id = '';

 
		}

$total_match_count = sizeof($id_ary);
if ($total_match_count)
{
// Limit the number to $total_matches_limit for pre-made searches
if ($total_match_count > $total_matches_limit)
{
$found_more_search_matches = true;
$total_match_count = $total_matches_limit;
}

// Make sure $start is set to the last page if it exceeds the amount
if ($start < 0)
{
$start = 0;
}
else if ($start >= $total_match_count)
{
$start = floor(($total_match_count - 1) / $per_page) * $per_page;
}

$id_ary = array_slice($id_ary, $start, $per_page);
}
else
{
// Set $start to 0 if no matches were found
$start = 0;

		}
}


		}
}


Line 511Line 538
	{
$firstpost_only = ($search_fields === 'firstpost' || $search_fields == 'titleonly') ? true : false;
$total_match_count = $search->author_search($show_results, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_id_ary, $sql_author_match, $id_ary, $start, $per_page);

	{
$firstpost_only = ($search_fields === 'firstpost' || $search_fields == 'titleonly') ? true : false;
$total_match_count = $search->author_search($show_results, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_id_ary, $sql_author_match, $id_ary, $start, $per_page);

	}

// For some searches we need to print out the "no results" page directly to allow re-sorting/refining the search options.
if (!sizeof($id_ary) && !$search_id)
{
trigger_error('NO_SEARCH_RESULTS');

 
	}

$sql_where = '';

	}

$sql_where = '';

Line 543Line 564
	$icons = $cache->obtain_icons();

// Output header

	$icons = $cache->obtain_icons();

// Output header

	if ($search_id && ($total_match_count > 1000))

	if ($found_more_search_matches)

	{

	{

		// limit the number to 1000 for pre-made searches
$total_match_count--;

 
		$l_search_matches = sprintf($user->lang['FOUND_MORE_SEARCH_MATCHES'], $total_match_count);
}
else

		$l_search_matches = sprintf($user->lang['FOUND_MORE_SEARCH_MATCHES'], $total_match_count);
}
else

Line 555Line 574
	}

// define some vars for urls

	}

// define some vars for urls

	$hilit = implode('|', explode(' ', preg_replace('#\s+#u', ' ', str_replace(array('+', '-', '|', '(', ')', '&quot;'), ' ', $keywords))));
// Do not allow *only* wildcard being used for hilight
$hilit = (strspn($hilit, '*') === strlen($hilit)) ? '' : $hilit;

	// A single wildcard will make the search results look ugly
$hilit = phpbb_clean_search_string(str_replace(array('+', '-', '|', '(', ')', '&quot;'), ' ', $keywords));
$hilit = str_replace(' ', '|', $hilit);


$u_hilit = urlencode(htmlspecialchars_decode(str_replace('|', ' ', $hilit)));
$u_show_results = '&amp;sr=' . $show_results;


$u_hilit = urlencode(htmlspecialchars_decode(str_replace('|', ' ', $hilit)));
$u_show_results = '&amp;sr=' . $show_results;

Line 578Line 597
	$template->assign_vars(array(
'SEARCH_TITLE' => $l_search_title,
'SEARCH_MATCHES' => $l_search_matches,

	$template->assign_vars(array(
'SEARCH_TITLE' => $l_search_title,
'SEARCH_MATCHES' => $l_search_matches,

		'SEARCH_WORDS'		=> $search->search_query,


		'SEARCH_WORDS'		=> $keywords,
'SEARCHED_QUERY' => $search->search_query,

		'IGNORED_WORDS'		=> (sizeof($search->common_words)) ? implode(' ', $search->common_words) : '',
'PAGINATION' => generate_pagination($u_search, $total_match_count, $per_page, $start),
'PAGE_NUMBER' => on_page($total_match_count, $per_page, $start),

		'IGNORED_WORDS'		=> (sizeof($search->common_words)) ? implode(' ', $search->common_words) : '',
'PAGINATION' => generate_pagination($u_search, $total_match_count, $per_page, $start),
'PAGE_NUMBER' => on_page($total_match_count, $per_page, $start),

Line 820Line 840
			$hilit_array = array_filter(explode('|', $hilit), 'strlen');
foreach ($hilit_array as $key => $value)
{

			$hilit_array = array_filter(explode('|', $hilit), 'strlen');
foreach ($hilit_array as $key => $value)
{

				$hilit_array[$key] = str_replace('\*', '\w*?', preg_quote($value, '#'));


				$hilit_array[$key] = phpbb_clean_search_string($value);
$hilit_array[$key] = str_replace('\*', '\w*?', preg_quote($hilit_array[$key], '#'));

				$hilit_array[$key] = preg_replace('#(^|\s)\\\\w\*\?(\s|$)#', '$1\w+?$2', $hilit_array[$key]);
}
$hilit = implode('|', $hilit_array);

				$hilit_array[$key] = preg_replace('#(^|\s)\\\\w\*\?(\s|$)#', '$1\w+?$2', $hilit_array[$key]);
}
$hilit = implode('|', $hilit_array);