Tweaking Searches
Updated 09/05 - Search Throttle
The search form that comes with default MT templates is very limited in what it lets you do - basically it only lets you search the current blog and allows you to not specify any oother options. Here are some things you can do with searches. The code listed here can go into any template but the code must be placed within the search form ie <form>....</form>. Also each block of code is independent. You don't need to use previous code for it to work - as long as it is placed within the search form it will work no matter what other code you have or have not implemented !
Search Where ?
Replace the search form code you have with something like this
<form method="get" action="<$MTCGIPath$><$MTSearchScript$>">
<label for="search" accesskey="4">Search: </label><br /><input type="text" name="search" size="20" alt="Search Term" id="search" /><br />
<input type="submit" value="Search" /><br />
Blogs: <input type="checkbox" name="IncludeBlogs" value="4" id="Main Blog" /><label for="Main Blog">Main Blog</label>
<input type="checkbox" name="IncludeBlogs" value="5" id="Sideblog" /> <label for="Sideblog">Sideblog</label><br />
</form>
You will of course need to adapt this, replace the numbers for value with the blog ids of your blogs (to find the blog id, go to the menu for your blog and look at the address bar, you'll see something like &blog_id=x where x is your blog id) You can duplicate the IncludeBlogs input for as many blogs as you need - just make sure you change the blog ids as well !
Search What?
You can specify what to search ie Entries, Coments or both with this simple snippet. Just add it within your search form
<input type="radio" name="SearchElement" value="entries" id="Entries" /> <label for="Entries">Entries</label> <input type="radio" name="SearchElement" value="comments" id="Comments" /> <label for="Comments">Comments</label> <input type="radio" name="SearchElement" value="both" id="Both" /> <label for="Both">Both</label>
Search When ?
You can specify the time frame to search, simply add this code to your search form
<select name="SearchCutoff">
<option value="7">one week back</option>
<option value="14">two weeks back</option>
<option value="30">one month back</option>
<option value="60">two months back</option>
<option value="90">three months back</option>
<option value="365">one year back</option>
<option value="99999">the beginning</option>
</select>
How Much
You can also specify how many results you wish to return from the search per blog. Again just add this code within your search form
<select name="MaxResults">
<option value="5">5</option>
<option value="10">10</option>
<option value="15">15</option>
<option value="25">25</option>
<option value="50">50</option>
<option value="100">100</option>
<option value="99999">All</option>
</select>
Case and Regex
There are two more things you can do. The first is match case, put this somewhere in your search form
<input type="checkbox" name="CaseSearch" id="Case" /> <label for="Case">Match case</label>
The next is a regex option (see What is a Regex Search ?). Put this code somewhere within your search form
<input type="checkbox" name="RegexSearch" id="Regex" /><label for="Regex">Regex Search</label>
With MT 3.1, a new feature called search throttle has been implemented. This feature prevents people from doing more than one search every minute - by the default setting. Now this is quite annoying so to change that you will need to edit the file Search.pm found in lib/MT/App. Towards the top you'll see something:
if ($time > time - 60) { ## Within the last minute.
The number (60) can be changed to whatever time length you want, it is in seconds. I have changed it to 20.
Etc.
You can do even more, see these tutorials:

elise said:
on Sep 5, 2004 9:43 PM | Reply
Hi Arvind, I checked the MT2.661 files and the search throttle is there too. The problem is that there is a bug in MT3.1 that prevents MT from recognizing that the search is complete so that you can start another one. Apparently they are working on the bug. I changed my throttle also, as a quick fix to this problem. But when they release the bug fix you may want to change the throttle back to 60. See the support thread:
Arvind Satyanarayan said:
on Sep 5, 2004 9:59 PM | Reply
Ah thanks Elise, but still you never know when you may want to change the search throttle feature !
Michael Ditto said:
on Apr 5, 2005 11:26 PM | Reply
Arvind, I am looking for a way to have the search always act as an "exact phrase" and complete word search without the user having to type quotes in.
I'm working on TalkLeft.com, and Jeralyn says that prior to upgrading to 3.15 it always behaved that way. For instance, she wants a search for [patriot act] to always return entries about the Patriot Act but not entries that say [joe blow, a true patriot, acted with valor]. Right now it's returning every entry that has any combination of partial words in it.
Here is the search form:
Michael Ditto said:
on Apr 6, 2005 9:57 PM | Reply
Never mind. I decided to hack Search.pm to do what I wanted. I'll post it on my web site whenever I figure out what the legalities are there.
Arson said:
on Feb 14, 2006 11:56 AM | Reply
Hello this has been an experience and its great just wanted to say hello . and hello to all
George Huff said:
on Jan 5, 2007 10:52 PM | Reply
I am running into throttle problems for Movable Type 3.33. I looked for the same bit of code as 3.1 and it's slightly different, as there is no exact number for the the throttle.
Looks like:
## Combine user-selected included/excluded blogs ## with config file settings. for my $type (qw( IncludeBlogs ExcludeBlogs )) { $app->{searchparam}{$type} = { }; if (my $list = $cfg->$type()) { $app->{searchparam}{$type} = { map { $_ => 1 } split /\s*,\s*/, $list }; } next if $no_override{$type}; for my $blog_id ($q->param($type)) { if ($blog_id =~ m/,/) { my @ids = split /,/, $blog_id; s/\D+//g for @ids; # only numeric values. foreach my $id (@ids) { next unless $id; $app->{searchparam}{$type}{$id} = 1; } } else { $blog_id =~ s/\D+//g; # only numeric values. $app->{searchparam}{$type}{$blog_id} = 1; } }Any thoughts? Thanks.
Arvind Satyanarayan said:
on Jan 6, 2007 10:22 AM | Reply
Hi George, the search throttle bug no longer exists in MT 3.33 so this hack is no longer necessary.
Babak said:
on Jan 6, 2007 1:06 PM | Reply
Thank you so much for this helpful article, I translated this to Persian and posted in my blog ! http://www.hazaveh.ir/archives/000998.php
TEKKOS said:
on Feb 9, 2007 10:52 AM | Reply
Arvind if I set ThrottleSeconds to let's say 3, I find I still have to wait longer than 3 sec. to be able to do a next search .... (this is with MT 3.33). Any thoughts?
James Keim said:
on Apr 25, 2007 2:35 AM | Reply
I am using 3.35 and I find that the Search Throttle is still not working right. I thought it was a result of switching to FastCGI but it seems to happen even when I disable FastCGI. Anyone else running into this?