Adding a "Search Again" box to the search template

Started by Tristan Perry, July 04, 2005, 12:44:14 PM

Previous topic - Next topic

Tristan Perry

Hello all,
This simple hack puts a search box on the search results page where you can change the search keywords used. This isn't much faster to search again than simply hitting back in your browser, although I think this looks better and is more convienient. This search box only appears if the "Revise your search box" doesn't show up.

In Search.template.php
Find the "
if (isset($context['did_you_mean']) || empty($context['topics']))" if statement, namely:

if (isset($context['did_you_mean']) || empty($context['topics']))
{
echo '
<table width="100%" cellpadding="4" cellspacing="0" border="0" class="tborder" style="margin-bottom: 2ex;">
<tr class="titlebg">
<td>', $txt['search_adjust_query'], '</td>
</tr>
<tr>
<td class="windowbg">';

// Did they make any typos or mistakes, perhaps?
if (isset($context['did_you_mean']))
echo '
', $txt['search_did_you_mean'], ' <a href="', $scripturl, '?action=search2;params=', $context['did_you_mean_params'], '">', $context['did_you_mean'], '</a>.<br />';

echo '
<form action="', $scripturl, '?action=search2" method="post" style="margin: 0;">
<b>', $txt[582], ':</b><br />
<input type="text" name="search"', !empty($context['search_params']['search']) ? ' value="' . $context['search_params']['search'] . '"' : '', ' size="40" />
<input type="submit" name="submit" value="', $txt['search_adjust_submit'], '" />

<input type="hidden" name="searchtype" value="', !empty($context['search_params']['searchtype']) ? $context['search_params']['searchtype'] : 0, '" />
<input type="hidden" name="userspec" value="', !empty($context['search_params']['userspec']) ? $context['search_params']['userspec'] : '', '" />
<input type="hidden" name="show_complete" value="', !empty($context['search_params']['show_complete']) ? 1 : 0, '" />
<input type="hidden" name="subject_only" value="', !empty($context['search_params']['subject_only']) ? 1 : 0, '" />
<input type="hidden" name="minage" value="', !empty($context['search_params']['minage']) ? $context['search_params']['minage'] : '0', '" />
<input type="hidden" name="maxage" value="', !empty($context['search_params']['maxage']) ? $context['search_params']['maxage'] : '9999', '" />
<input type="hidden" name="sort" value="', !empty($context['search_params']['sort']) ? $context['search_params']['sort'] : 'relevance', '" />';

if (!empty($context['search_params']['brd']))
foreach ($context['search_params']['brd'] as $board_id)
echo '
<input type="hidden" name="brd[', $board_id, ']" value="', $board_id, '" />';

echo '
</form>
</td>
</tr>
</table>';
}


And add below it:

else
{
echo '<table width="100%" cellpadding="4" cellspacing="0" border="0" class="tborder" style="margin-bottom: 2ex;">
<tr class="titlebg">
<td>Change Search Keywords</td>
</tr>
<tr>
<td class="windowbg">
<form action="', $scripturl, '?action=search2" method="post" style="margin: 0;">
<b>', $txt[582], ':</b><br />
<input type="text" name="search"', !empty($context['search_params']['search']) ? ' value="' . $context['search_params']['search'] . '"' : '', ' size="40" />
<input type="submit" name="submit" value="Search Again" />

<input type="hidden" name="searchtype" value="', !empty($context['search_params']['searchtype']) ? $context['search_params']['searchtype'] : 0, '" />
<input type="hidden" name="userspec" value="', !empty($context['search_params']['userspec']) ? $context['search_params']['userspec'] : '', '" />
<input type="hidden" name="show_complete" value="', !empty($context['search_params']['show_complete']) ? 1 : 0, '" />
<input type="hidden" name="subject_only" value="', !empty($context['search_params']['subject_only']) ? 1 : 0, '" />
<input type="hidden" name="minage" value="', !empty($context['search_params']['minage']) ? $context['search_params']['minage'] : '0', '" />
<input type="hidden" name="maxage" value="', !empty($context['search_params']['maxage']) ? $context['search_params']['maxage'] : '9999', '" />
<input type="hidden" name="sort" value="', !empty($context['search_params']['sort']) ? $context['search_params']['sort'] : 'relevance', '" />';
echo '</form>
</td>
</tr>
</table>';
}


That's it, you can see a working example of this on my forums.
Tau Online

Advertisement: