Browse Source

Friendly warning if using short terms in search, instead of failing badly

Signed-off-by: emanuele <[email protected]>
emanuele 12 years ago
parent
commit
e226a621d1

+ 2 - 1
Sources/Search.php

@@ -688,6 +688,7 @@ function PlushSearch2()
 	// The remaining words and phrases are all included.
 	$searchArray = array_merge($phraseArray, $wordArray);
 
+	$context['search_ignored'] = array();
 	// Trim everything and make sure there are no words that are the same.
 	foreach ($searchArray as $index => $value)
 	{
@@ -703,7 +704,7 @@ function PlushSearch2()
 		// Don't allow very, very short words.
 		elseif ($smcFunc['strlen']($value) < 2)
 		{
-			$context['search_errors']['search_string_small_words'] = true;
+			$context['search_ignored'][] = $value;
 			unset($searchArray[$index]);
 		}
 		else

+ 9 - 1
Themes/default/Search.template.php

@@ -26,6 +26,10 @@ function template_main()
 		echo '
 		<p class="errorbox">', implode('<br />', $context['search_errors']['messages']), '</p>';
 
+	if (!empty($context['search_ignored']))
+		echo '
+		<p class="noticebox">', $txt['search_warning_ignored_word' . (count($context['search_ignored']) == 1 ? '' : 's')], ': ', implode(', ', $context['search_ignored']), '</p>';
+
 	// Simple Search?
 	if ($context['simple_search'])
 	{
@@ -238,7 +242,7 @@ function template_results()
 {
 	global $context, $settings, $options, $txt, $scripturl, $message;
 
-	if (isset($context['did_you_mean']) || empty($context['topics']))
+	if (isset($context['did_you_mean']) || empty($context['topics']) || !empty($context['search_ignored']))
 	{
 		echo '
 	<div id="search_results">
@@ -254,6 +258,10 @@ function template_results()
 			echo '
 			<p>', $txt['search_did_you_mean'], ' <a href="', $scripturl, '?action=search2;params=', $context['did_you_mean_params'], '">', $context['did_you_mean'], '</a>.</p>';
 
+		if (!empty($context['search_ignored']))
+			echo '
+			<p>', $txt['search_warning_ignored_word' . (count($context['search_ignored']) == 1 ? '' : 's')], ': ', implode(', ', $context['search_ignored']), '</p>';
+
 		echo '
 			<form action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '">
 				<dl class="settings">

+ 2 - 0
Themes/default/languages/Search.english.php

@@ -101,6 +101,8 @@ $txt['search_error_max_percentage'] = 'Invalid percentage of words to be skipped
 $txt['error_string_too_long'] = 'Search string must be less than %1$d characters long.';
 
 $txt['search_adjust_query'] = 'Adjust Search Parameters';
+$txt['search_warning_ignored_word'] = 'The following term has been ignored in your search because too short';
+$txt['search_warning_ignored_words'] = 'The following terms have been ignored in your search because too short';
 $txt['search_adjust_submit'] = 'Revise Search';
 $txt['search_did_you_mean'] = 'You may have meant to search for';