Movable Type User Manual: PUBLIC SEARCH

« Table of Contents


PUBLIC SEARCH

Movable Type's public search interface is an integration of Jay Allen's mt-search add-on for Movable Type. The search engine supports two different types of search: straight keyword search and new comment search. The straight search supports boolean queries, phrase searching, and regular expression matching (if desired). The new comment search (actually, most of a ``listing'' than a search) lists all of the new comments posted on entries on your site in a specified interval.

Search queries are logged in your site's activity log.

Search Templates

Search templates are not managed like other templates in the Movable Type system, because they are not managed on a per-weblog basis, and thus do not make sense in the ``Templates'' section of the editing menu. Search templates are files in your search_templates/ directory; this directory should be located in the same directory as mt.cgi.

In your search templates, you can use a special set of template tags to display the results for a search. You can also use most other Movable Type tags, although, of course, you must respect the context in which you are using the tags. In addition, since your search results page is dynamic and will be rebuilt every time anyone makes a search on your site, you should be careful about using any tags that would require a lot of server resources and time to build (for example, <MTArchiveList> or <MTCalendar>).

You can also use the <MTInclude> tag in your search templates to include template modules or external files. You can even use tags like this, which require a weblog to be in context (because template modules are stored on a per-weblog basis), outside of the <MTSearchResults> container. However, there are caveats with this method, and you should be careful with using this if you have multiple weblogs. For example, if you use

<$MTInclude module="Header"$>

in a template, the system needs to know which weblog to look in for the module named Header. If there are search results found, the system will look in the weblog that is earliest alphabetically; if there are no search results, Movable Type will simply try to load a weblog from your database (the determination of the weblog that is chosen is undefined).

This behavior may be refined in the future.

Search Forms

The Movable Type default templates include a simple search form to search the weblogs on your site. This form looks like this:

<form method="get" action="<$MTCGIPath$><$MTSearchScript$>">
<label for="search" accesskey="4">Search this site:</label><br />
<input id="search" name="search" size="20" /><br />
<input type="submit" value="Search" />
</form>

A full search form, with all options visible, would look something like this:

<form method="post" action="<$MTCGIPath$><$MTSearchScript$>">
<input size="30" name="search" value="<$MTSearchString$>" />
<input type="submit" value="Search" /><br />
<input type="checkbox" name="CaseSearch" /> Match case 
<input type="checkbox" name="RegexSearch" /> Regex search<br />
<b>Search:</b>
<input type="radio" name="SearchElement" value="entries" /> Entries 
<input type="radio" name="SearchElement" value="comments" /> Comments 
<input type="radio" name="SearchElement" value="both" /> Both <br />
<b>Sort By:</b>
<select name="SearchSortBy">
<option value="created_on">Authored On Date</option>
<option value="title">Title</option>
</select><br />
<b>Sort Order:</b>
<select name="ResultDisplay">
<option value="ascend">Ascending</option>
<option value="descend">Descending</option>
</select><br />
<b>Exclude Weblogs:</b>
<MTBlogs>
<input type="checkbox" name="ExcludeBlogs" value="<$MTBlogID$>" /> <$MTBlogName$>
</MTBlogs><br />
<b>Search entries from:</b>
<select name="SearchCutoff">
<option value="9999999">the beginning</option>
<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>
</select><br />
<b>Results per weblog:</b>
<select name="MaxResults">
<option value="5">5</option>
<option value="10">10</option>
<option value="25">25</option>
<option value="50">50</option>
<option value="100">100</option>
<option value="9999999">All</option>
</select>
</form>

This search form gives the user more control over the parameters of the search, allowing him to specify constraints such as case-matching, or using a regular expression match instead of a boolean query. The search can also be confined to either entries or comments (or both). Note that a comment search is more time- and resource-intensive than an entry search.

The above form also includes the ability to exclude certain weblogs from the search. This is useful if a visitor wishes to search only in one of your weblogs. As an alternative to the Exclude Weblogs, you could instead use the following:

<b>Include Weblogs:</b>
<MTBlogs>
<input type="checkbox" name="IncludeBlogs" value="<$MTBlogID$>" /> <$MTBlogName$>
</MTBlogs><br />

This is essentially the inverse of the Exclude Weblogs setting, but may be preferable to you for whatever reason. For example, it makes it easier to create weblog-specific search results pages--instead of maintaining the lists of weblogs to exclude, you need only add this to the form:

<input type="hidden" name="IncludeBlogs" value="<$MTBlogID$>" />

<$MTBlogID$> always references the current weblog, so this search will always be restricted to just the weblog being viewed.

The above search forms are used for the straight search. A full new comment search form might look like this:

<form method="post" action="<$MTCGIPath$><$MTSearchScript$>">
<input type="hidden" name="Type" value="newcomments" />
<b>Exclude Weblogs:</b>
<MTBlogs>
<input type="checkbox" name="ExcludeBlogs" value="<$MTBlogID$>" /> <$MTBlogName$>
</MTBlogs><br />
<b>Search entries from:</b>
<select name="CommentSearchCutoff">
<option value="9999999">the beginning</option>
<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>
</select><br />
<b>Number of entries to return:</b>
<select name="MaxResults">
<option value="5">5</option>
<option value="10">10</option>
<option value="25">25</option>
<option value="50">50</option>
<option value="100">100</option>
<option value="9999999">All</option>
</select><br />
<input type="submit" value="Find new comments" />
</form>

Alternate Templates

Typically, when a search is performed the default search template (default.tmpl) is rendered in order to display the results (or, in the case of a new comment search, the template comments.tmpl is used). If you have multiple weblogs, though, and you are using the search tool for each of those weblogs, you might want the search results from one weblog to look different than the results from another weblog. Or, you might have several different versions of your public site: a graphics-heavy version for normal viewers, and a text-heavy version without graphics for handheld devices. You would like the search results to be consistent with the look and feel of the rest of your site, whichever version of the site your visitor is using.

To do this, you can use alternate templates. For example, each weblog can have its own search results template that matches with its own design; or each version of your site can have its own search results template.

  1. Create the templates.
    For each different look and feel that you want, create a search results template, and put them in your search_templates/ directory.

  2. Add the templates to your configuration.
    Open up your mt.cfg file in a text editor, and use the AltTemplate directive to configure the alternate templates. For example, if you have two weblogs (Work and Play), and you want each weblog to have its own template, you might add something like this:
    AltTemplate work work.tmpl
    AltTemplate play play.tmpl
    

  3. Configure the search form.
    To tell Movable Type which template to use when building the search results pages, you use a hidden form input. Add this to the search form on your Work weblog, for example:
    <input type="hidden" name="Template" value="work" />
    

    (Note: if you wish to restrict the search to just this one weblog, you may also want to add

    <input type="hidden" name="IncludeBlogs" value="<$MTBlogID$>" />
    

    to the form.)

Converting from previous versions of mt-search

If you were using Jay's search engine, you'll need to convert to using the integrated version. Follow these steps:

  1. Upgrade your copy of Movable Type.
    You may have already done this, but you will need to upgrade to Movable Type version 2.5, which contains the integrated search engine.

  2. Copy configuration settings.
    Now that the search engine has been integrated into Movable Type, there is no longer a need to use two separate configuration files (mt-search.cfg and mt.cfg). The new version of the search engine expects your search configuration in your standard mt.cfg file.

    So, you will need to open up both mt.cfg and mt-search.cfg in a text editor, and copy all of the contents of mt-search.cfg into mt.cfg.

  3. Update your AltTemplate settings.
    The new version of search uses a simplified AltTemplate format and allows you to specify an infinite number of alternate templates. If you are currently using alternate templates with mt-search, you will need to change your AltTemplateN directives to AltTemplate. In other words, replace the number at the end of the directive. For example, if you had this:
    AltTemplate1 work work.tmpl
    

    you would change it to

    AltTemplate work work.tmpl
    

  4. Rename your TemplateDir setting.
    To eliminate confusion with the TemplatePath setting, the new version of search has renamed the TemplateDir setting to SearchTemplatePath. So if you had this:
    TemplateDir /path/to/search_templates
    

    you would change it to

    SearchTemplatePath /path/to/search_templates
    


Copyright © 2001-2004 Six Apart. All Rights Reserved.