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
You can search for exact words in a post by putting them in quotation marks "like this", but how do I make it so people don't have to put a post in quotation marks to get an exact search?

How do I make exact search the default so people don't have to use quotation marks for exact search?
Does anyone know how to do this?

Is there a way to add quotation marks around each search?

Like if I searched for videos the forum would automatically put quotation marks around it like "videos"
You might try looking at /inc/functions_search.php to see what you can find. I believe that is where it actually fetches the results.
Thanks but what code do I add to automatically add quotation marks to searches?
Can anyone help with this?
Are you referring to quick search or the extended search option?
It also means that some flexibility gets lost, like you have when you want to input more keywords that do not have to be in the same order and with other text in between.
(2015-01-23, 04:23 PM)Ad Bakker Wrote: [ -> ]Are you referring to quick search or the extended search option?
It also means that some flexibility gets lost, like you have when you want to input more keywords that do not have to be in the same order and with other text in between.

I'm referring to both.

This is for a forum where mostly links are posted, so an exact search as the default would be perfect for it.
OK, I will see what I can do. Wait a while, because it's dinner time here. Smile 
Thanks man! looking forward to it.
OK, is still before dinner Smile .

Copy the code below, and store it as "search_exact.php":

<?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()
{
	global $mybb;
	$mybb->input['keywords'] = "\"{$mybb->input['keywords']}\"";
}
?>

Then copy this file to your inc/plugins directory.
In your AdminCP go to "plugins" and activate the plugin "search_exact".
Then test it, I did 1 test and it worked with me.

EDIT
Remember that no double quotes (") are allowed within the search text.
Pages: 1 2 3