OpenSearch standard using Movable Type

OpenSearch is a search plugin technology building on RSS to allow content providers to enable searches from a multitude of sites from a common search protocol. You too can have an OpenSearch column using your Movable Type weblog and some small configuration tweaks. I will walk you through the necessary steps to create an OpenSearch channel for your Movable Type weblog. This hack is for advanced users who are comfortable editing their Movable Type configuration file. You break it, you fix it.

Create a new search template

First you need to create a new search template. Create a new text file named osrss.tmpl containing the text below or copy from this text file.

<?xml version="1.0" encoding="<$MTPublishCharset$>"?>
<rss version="2.0" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/">
<channel><MTSearchResults><MTBlogResultHeader>
<title><$MTBlogName remove_html="1" encode_xml="1"$> results for <$MTSearchString$></title>
<link><$MTBlogURL remove_html="1" encode_xml="1"$></link>
<description><$MTBlogDescription remove_html="1" encode_xml="1"$></description>
<managingEditor><MTEntries lastn="1"><$MTEntryAuthorEmail$></MTEntries></managingEditor>
<webMaster><MTEntries lastn="1"><$MTEntryAuthorEmail$></MTEntries></webMaster>
<language>en-us</language>
<pubDate><$MTDate format="%a, %d %b %Y %H:%M:%S "$><$MTBlogTimezone no_colon="1"$></pubDate>
<docs>http://blogs.law.harvard.edu/tech/rss</docs>
<generator>Movable Type <$MTVersion$></generator>
<ttl>1440</ttl>
<openSearch:totalResults><$MTSearchResultCount$></openSearch:totalResults>
<openSearch:startIndex>1</openSearch:startIndex>
<openSearch:itemsPerPage><$MTSearchResultCount$></openSearch:itemsPerPage>
</MTBlogResultHeader><item>
<title><$MTEntryTitle remove_html="1" encode_xml="1"$></title>
<link><$MTEntryLink encode_xml="1"$></link>
<description><$MTEntryExcerpt encode_xml="1"$></description>
<pubDate><$MTEntryDate format="%a, %d %b %Y %H:%M:%S "$><$MTBlogTimezone no_colon="1"$></pubDate>
<guid isPermaLink="true"><$MTEntryLink encode_xml="1"$></guid>
<author><$MTEntryAuthorEmail$> (<$MTEntryAuthor$>)</author>
<MTEntryIfAllowComments>
<comments><$MTCGIPath$><$MTCommentScript$>?entry_id=<$MTEntryID$></comments>
</MTEntryIfAllowComments>
<MTIfNonEmpty tag="MTEntryCategory">
<category domain="<$MTBlogArchiveURL$>">
<MTParentCategories glue="/"><MTCategoryLabel dirify="1" encode_xml="1"></MTParentCategories>
</category></MTIfNonEmpty>
</item>
</MTSearchResults></channel>
</rss>

Next you will need to upload this search template to your search_templates directory inside your Movable Type installation.

Edit your Movable Type configuration file

Open mt.cfg in the root directory of your Movable Type installation. Find your alternative template section of your configuration file — search for AltTemplate — and add the line below.

AltTemplate osrss osrss.tmpl

Save your configuration file and exit.

Create your OpenSource description

Next you need to create a special XML to describe your search channel to Amazon. Follow the sample markup for the OpenSource description format and create your own description file. You can take a look at my OpenSearch description document for guidance. Upload your completed file to your weblog’s root directory.

You need to use a special URL in the descriptor to call the results of your newly created template.

<Url>PATH TO MT/mt-search.cgi?IncludeBlogs=WEBLOG ID&amp;SearchElement=entries&amp;SearchCutoff=9999999&amp;Template=osrss&amp;search={searchTerms}</Url>

Please note that you must escape the ampersands.

Description of variables
PATH TO MT
The location of your Movable Type installation.
WEBLOG ID
The numeric value corresponding to the weblog against which you would like to conduct a search.
SearchElement
Enter entries to search just weblog entries, comments to search just comments, or both to search both entries and comments.
SearchCutoff
Restrict your search to a number of days in the past. Setting this value to a very large number will allow a search of all your designated content.

Submit your search

That’s it! Submit your OpenSearch search to Amazon and run a test query to make sure you set everything up correctly.