Searching Groups Of Blogs 1.0

December 13, 2003 - updated February 8, 2006

The MovableType search forms allow you to limit which Blogs to search by specifying IncludeBlogs and/or ExcludeBlogs one blog ID at a time. This means that for every blog you want to specify, there has to be a checkbox or hidden input field. This hack modifies MovableType so that you can specify more than one blog ID with an Include/ExcludeBlogs parameter. This allows you, for example, to present the user with a single checkbox or menu item that allows them to search through mutlitple blogs.

lib/MT/App/Search.pm Modification

This modification allows you to specify more than one blog ID (separated by comma) in the IncludeBlogs and ExcludeBlogs fields of a search template.
  1. Open the file Search.pm in the lib/MT/App directory.
  2. Find the code that says:
            for my $blog_id ($q->param($type)) {
                $app->{searchparam}{$type}{$blog_id} = 1;
            }
  3. Replace it with thefollowing code:
    	# BEGIN Searching Groups Of Blogs HACK
    	# http://www.nonplus.net/software/mt/SearchingGroupsOfBlogs.htm
            for my $blog_ids ($q->param($type)) {
                for my $blog_id ( split /\s*,\s*/, $blog_ids) {
                    $app->{searchparam}{$type}{$blog_id} = 1;
                }
            }
    	# END Searching Groups Of Blogs HACK
    

Modifying your Search Form

After you modify the Search.pm file, you can modify your search form to include multiply BlogIDs in IncludeBlogs and ExcludeBlogs fields. The following code displays a menu with three option, each of which will search through different blogs:
<select name="IncludeBlogs">
    <option value="1,2,3">All blogs</option>
    <option value="2,3">Art blogs</option>
    <option value="1">Journal</option>
    <option value="2">Photos</option>
    <option value="3">Drawings</option>
</select>