The Movable Type User Manual

NOTE: This documentation is for Movable Type 3.2. If you are using a newer version, please see the documentation for Movable type 3.3x or Movable Type Enterprise.

« Introduction | Up | Creating a Search Form »

Chapter 10: Search

Configuring Search for One or More Weblogs

You want to enable your system to provide users with search capabilities across one or more weblogs.

Solution

Add configuration directives to mt-config.cgi that are related to the search engine.

Discussion

The MT search engine features a number of configurable options which are maintained in the mt-config.cgi file rather than in a web interface. The search functionality is not tied to a specific weblog, and its configuration is applied system wide.

Because these functions are not tied to a specific weblog and due to the dynamic nature of its pages, search templates are stored as files in the search_templates directory located under the MT home directory.

When the mt-search.cgi script is called, the templates are read in, translated into HTML::Template layouts, and generated through the MT::App subclass, MT::App::Search. So in essence, search templates are spoofed and not true MT templates.

HTML::Template is the CPAN module that MT uses for all of its administrative scripts' templates such as mt.cgi. This module is better tuned for dynamic template generation, but is less user-friendly for non-developers to customize and requires that all data and formatting be prepared in Perl before it is invoked. MT Search attempts to balance the trade-offs between these two template generation methods. You can use most other Movable Type tags just as you can in standard templates, although some issues and inconsistencies do exist. For instance, since this page is generated each time a reader executes a search, using any tags that would require a lot of server resources and time (for example, MTArchiveList or MTCalendar) should be strictly avoided.

Also note that given the nature of the result-generation process, MT search template tags are only recognized in these specific templates and nowhere else.

Configuring the built-in search engine

As previously mentioned, the built-in search capabilities of MT are configured through the mt-config.cgi file. Here we review the directives related to the search functionality.

  • SearchScript

    This is the site URI for the search script. By default this is set to mt-search.cgi in the MT home directory.

  • SearchTemplatePath

    This optional directive allows for search templates to be stored in a different path. The default is ./search_templates relative to the MT home directory.

  • DefaultTemplate

    The filename of the default search template directory specified by the SearchTemplatePath directive. The default value is 'default.tmpl'.

  • AltTemplate

    This directive allows for systems hosting multiple weblogs to provide different search result layouts. Configuration values are in the form of key template_filename. For instance if you wanted to create an alternate template for "play," you would add a directive of...

     AltTemplate play play.tmpl

    ...where play.tmpl represents a search template in the configured path.

    You can define as many alternate templates as you want. The keys cannot be duplicated.

    See "Adding Alternate Search Templates" for more information on how this directive can be used.

  • ExcludeBlogs
  • IncludeBlogs

    Since the search functionality is a system resource, these directives are included to restrict which weblogs are searchable. These directives are essentially mutually exclusive and are not recommended for use simultaneously. (IncludeBlogs will override ExcludeBlogs.) The default is to search all system weblogs. The values of the directives are expected to be weblog IDs. Multiple weblogs can be specified with commas.

  • RegexSearch
  • CaseSearch

    These directives specify the default values for searches. These boolean settings can be overridden through form inputs. RegexSearch allows for regular-expression syntax to be used. CaseSearch allows for searches to be case-sensitive. The default value for each of these settings is 0 (false).

  • SearchCutoff
  • CommentSearchCutoff

    These directives set the number of days to filter a search or a comment search: SearchCutoff and CommentSearchCutoff respectively. The default for SearchCutoff is to search all entries in a weblog. Comment search default to entries made in the last month.

  • MaxResults

    An integer specifying the default number of results to return.

    NOTE: In regards to comment searches, this directive specifies the number of entries with comments and not the number of comments to display.

  • ResultsDisplay

    The sort order for the search results based on their created-on timestamp. The value of this directive must be 'ascend' or 'descend.' The default is 'descend.'

  • ExcerptWords

    Since the search functionality is not tied to a specific weblog, any configured limits on auto-generated excerpts via the MTEntryExcerpt are not applicable. The default is 40 words.

  • SearchElement

    This directive determines which weblog entities to perform a search on. Possible values are 'entries,' 'comments,' or 'both.' The default is 'entries.'

    NOTE: A comment search is more resource intensive and can take a considerable amount of time to perform if the weblog(s) has/have an extensive number of comments.

  • NoOverride

    This directive locks the search configuration from being overridden in a search query. By default, the built-in search engine allows most of the above configuration directives to be overridden by parameters passed into the mt-search.cgi script. This can have damaging side effects in that a user could override those settings through URL manipulation. This could be exploited to display hidden private weblogs by overriding the ExcludeBlogs or IncludeBlogs directives.

    The value of this directive is a comma-separated list of the other search directives that cannot be overridden. By default none of the configuration directives are locked.

Submit Feedback on This Article

Your comments on how we can improve this article are appreciated; but please do not use the feedback form to submit support requests or question. We will not respond to or publish such queries submitted through this form. If you have a technical question or problem, visit Movable Type Support.

Six Apart
Makers of weblog software and services for individuals, organizations and businesses.
This website is powered by Movable Type.