Require minimum number of characters in search

Started by Metho, August 18, 2004, 09:24:30 PM

Previous topic - Next topic

Metho

I saw AMA did a little nifty thing with JS to accomplish this, and I agreed with Tomer that php would just generally be better for it. Maybe I'm wrong, but I thought I'd give everyone the option to choose php or JS for this. Mainly I did it to play with SMF, as this is the first chance I've actually forced myself to sit down for ten minutes and actually have fun with it! I have to give congrats to the dev team. The code is so much more refined, both in structure, use, and ease than yabbse, which is saying a lot. Thanks guys, and I hope I'll start doing more things, both big and small, to give back.

- Methonis

****INSTRUCTIONS****

1. Download the php file (http://www.four-walls.net/downloads/searchmin.zip and upload it to your server. Execute the file to insert the values into your database settings. (ex. If you upload searchminchar_db.php to www.yourdomain.com/forum, open your browser and type in http://www.yourdomain.com/forum/searchminchar_db.php to execute the script.

There is no MOD file right now, but the changes are limited, so make the changes in these files:

In Search.php, FIND: fatal_lang_error('no_valid_search_string', false);

ADD AFTER: if ($modSettings['searchminEnable'] == '1' && strlen($search_params['search']) < $modSettings['searchminChar'])
fatal_error('Sorry, you must have at least ' . $modSettings['searchminChar'] . ' characters to search.');


In ModSettings.php, FIND: array('int', 'search_results_per_page'),

ADD AFTER:         array('check', 'searchminEnable', null, &$txt['search_min_enable']),
array('int', 'searchminChar', null, &$txt['search_min_char']),


In ModSettings.english.php, FIND:$txt['search_weight_first_message'] = 'Relative search weight for a first message match';

ADD AFTER:$txt['search_min_enable'] = 'Require a minimum number of characters for search';
$txt['search_min_char'] = 'Minimum number of characters to search for';



That should be it. Now in Edit Features and Options in the Search category you will have two new options. Check the box to enable the feature, and put the a number in the box to dictate the MINIMUM number of characters to allow a search. It defaults the 3 when first installed.

Hope to get someone to confirm this is working. I did it quickly, and quite possibly forgot something. I'll release a mod file soon so you hopefully won't have to do it manually. Have fun.

*This useless feature brought to you by: Methonis - Creating bloat since YaBBSE*
Joshua "Methonis" Frazer
Support Specialist
The Simple Machines Team

A.M.A

Well done .. though I did not try it yet .. but it looks like it should work .. dare to say it should be a standard feature :)

now all what left is to make search remembers when was the last search done by a user to restrict him to a specific time .. but I guess it is much .. way too much :)

thanks for the effort.
Really sorry .. real life is demanding my full attention .. will be back soon hopefully :)

Metho

Was your idea in the first place, and I rather liked it and saw the sense in it. I just have a fear of anything non-php so I had to port it. :P

- Methonis
Joshua "Methonis" Frazer
Support Specialist
The Simple Machines Team

shark

Im using SMF 1.1 RC1.

I cant find this code in search.php
fatal_lang_error('no_valid_search_string', false);

Pls help.

Ben_S

Liverpool FC Forum with 14 million+ posts.

shark

Oh. I've run the searchminchar_db.php.
How can i reverse it back?

Advertisement: