Advertisement:

Author Topic: Require minimum number of characters in search  (Read 14995 times)

Offline Metho

  • SMF Friend
  • Full Member
  • *
  • Posts: 564
  • Gender: Male
Require minimum number of characters in search
« on: August 18, 2004, 09:24:30 PM »
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:
Code: [Select]
fatal_lang_error('no_valid_search_string', false);
ADD AFTER:
Code: [Select]
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:
Code: [Select]
array('int', 'search_results_per_page'),
ADD AFTER:
Code: [Select]
        array('check', 'searchminEnable', null, &$txt['search_min_enable']),
array('int', 'searchminChar', null, &$txt['search_min_char']),

In ModSettings.english.php, FIND:
Code: [Select]
$txt['search_weight_first_message'] = 'Relative search weight for a first message match';
ADD AFTER:
Code: [Select]
$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

Offline A.M.A

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 2,133
  • Gender: Male
  • ..
Re: Require minimum number of characters in search
« Reply #1 on: August 20, 2004, 09:16:46 PM »
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 :)

Offline Metho

  • SMF Friend
  • Full Member
  • *
  • Posts: 564
  • Gender: Male
Re: Require minimum number of characters in search
« Reply #2 on: August 20, 2004, 10:27:12 PM »
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

Offline shark

  • Semi-Newbie
  • *
  • Posts: 53
Re: Require minimum number of characters in search
« Reply #3 on: October 15, 2005, 05:37:58 AM »
Im using SMF 1.1 RC1.

I cant find this code in search.php
Code: [Select]
fatal_lang_error('no_valid_search_string', false);
Pls help.

Offline Ben_S

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 11,702
  • xxx
Re: Require minimum number of characters in search
« Reply #4 on: October 15, 2005, 05:46:29 AM »
1.1 has a rewritten search en gine.,
Liverpool FC Forum with 14 million+ posts.

Offline shark

  • Semi-Newbie
  • *
  • Posts: 53
Re: Require minimum number of characters in search
« Reply #5 on: October 15, 2005, 05:48:54 AM »
Oh. I've run the searchminchar_db.php.
How can i reverse it back?