MyBB Community Forums

Full Version: How to Make Exact Search the default
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
Everything works! Thanks for all your help! Big Grin
I will send you a last version with a text area for input which can also be extended manually.
Coming in a few minutes.

Last version with text box:


<?php
/**
 * Disallow direct access to this file for security reasons
 * 
 */
if(!defined("IN_MYBB"))
{
 die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
} 
$plugins->add_hook("search_do_search_start", "search_exact");
/**
 * Standard MyBB info function
 * 
 */
function search_exact_info() 
{
    global $lang;
    return Array(
        'name'          => "search_exact",
        'description'   => "search with keywords placed within quotes (exact search)", 
        'website'       => '',
        'author'        => 'Ad Bakker', 
        'authorsite'    => '',
        'version'       => '1.0',
        'guid'          => '',
        'compatibility' => '18*',
    );
}

function search_exact_activate()
{
    require_once(MYBB_ROOT . '/inc/adminfunctions_templates.php');
 find_replace_templatesets('search', '#' . preg_quote('<input type="text" class="textbox" name="keywords" size="35" maxlength="250" />') . '#','<textarea name="keywords" cols="60" rows="10"></textarea>'); 
}

function search_exact_deactivate()
{
    require_once(MYBB_ROOT . '/inc/adminfunctions_templates.php');
 find_replace_templatesets('search', '#' . preg_quote('<textarea name="keywords" cols="60" rows="10"></textarea>') . '#','<input type="text" class="textbox" name="keywords" size="35" maxlength="250" />');
}

function search_exact()
{
 global $mybb, $templates;
 $mybb->input['keywords'] = "\"{$mybb->input['keywords']}\"";
}
?>

Have a nice time!!
Wow it looks great! You're awesome!
Exact search as the default wasn't working for the search thread option at the bottom of threads, so I messaged Ad Bakker and he made it work.

He said to add

$plugins->add_hook("search_thread_start", "search_exact"); 

right below

$plugins->add_hook("search_do_search_start", "search_exact");

and that will make it work.

So the new full code will look like this:

<?php
/**
 * Disallow direct access to this file for security reasons 
 * 
 */
if(!defined("IN_MYBB"))
{
    die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}
$plugins->add_hook("search_do_search_start", "search_exact");
$plugins->add_hook("search_thread_start", "search_exact");
/**
 * Standard MyBB info function
 * 
 */
function search_exact_info()
{
    global $lang;
    return Array(
        'name'          => "search_exact",
        'description'   => "search with keywords placed within quotes (exact search)",
        'website'       => '',
        'author'        => 'Ad Bakker',
        'authorsite'    => '',
        'version'       => '1.0',
        'guid'          => '',
        'compatibility' => '18*',
    );
}

function search_exact()
{
    global $mybb;
    $mybb->input['keywords'] = "\"{$mybb->input['keywords']}\"";
}
?>
Pages: 1 2 3