OpenSearch Description and Atom-based Response templates for Movable Type

·

An OpenSearch 1.1 Description index template for Movable Type (served as opensearchdescription.xml):


<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
    <ShortName><$MTBlogName remove_html="1" encode_xml="1" trim_to="16"$></ShortName>
    <Description><$MTBlogDescription remove_html="1" encode_xml="1" trim_to="1024"$></Description>
    <Contact>you@example.com</Contact>
    <Url type="application/atom+xml" template="<$MTCGIPath$><$MTSearchScript$>?IncludeBlogs=<$MTBlogID$>&search={searchTerms}&Template=opensearch"/>
    <Url type="text/html" template="<$MTCGIPath$><$MTSearchScript$>?IncludeBlogs=<$MTBlogID$>&search={searchTerms}"/>
    <LongName><$MTBlogName remove_html="1" encode_xml="1"$></LongName>
    <Image height="16" width="16" type="image/vnd.microsoft.icon"><$MTBlogURL$>favicon.ico</Image>
</OpenSearchDescription>

and an OpenSearch 1.1 Response search template for Movable Type (using extensions to Atom 1.0, saved as opensearch.tmpl and served by the normal search script):


<?xml version="1.0" encoding="<$MTPublishCharset$>"?>
<feed
    xmlns="http://www.w3.org/2005/Atom"
    xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/">
    <MTSearchResults>
    <MTBlogResultHeader>
    
    <title><$MTBlogName remove_html="1" encode_xml="1"$>: search results for <$MTSearchString remove_html="1" encode_xml="1"$></title>
    <id>tag:<$MTBlogHost exclude_port="1" encode_xml="1"$>,<$MTDate format="%Y"$>:<$MTBlogRelativeURL encode_xml="1"$>/<$MTBlogID$>/opensearch/<$MTSearchString remove_html="1" encode_xml="1"$></id>
    <link rel="self" type="application/atom+xml" href="<$MTCGIPath$><$MTSearchScript$>?IncludeBlogs=<$MTBlogID$>&search=<$MTSearchString remove_html="1" encode_xml="1"$>&Template=opensearch"/>
    <link rel="alternate" type="text/html" href="<$MTCGIPath$><$MTSearchScript$>?IncludeBlogs=<$MTBlogID$>&search=<$MTSearchString remove_html="1" encode_xml="1"$>" />
    <author>
        <name>Your Name</name>
        <email>you@example.com</email>
    </author>
    <icon>http://<$MTBlogHost encode_xml="1"$>/favicon.ico</icon>
    <updated><MTEntries lastn="1"><$MTEntryModifiedDate utc="1" format="%Y-%m-%dT%H:%M:%SZ"$></MTEntries></updated>
    
    <opensearch:Query role="request" searchTerms="<$MTSearchString remove_html="1" encode_xml="1"$>" />
    <opensearch:totalResults><$MTSearchResultCount$></opensearch:totalResults>
    <opensearch:startIndex>1</opensearch:startIndex>
    <opensearch:itemsPerPage><$MTSearchResultCount$></opensearch:itemsPerPage>
    <opensearch:link rel="search" href="<$MTBlogURL$>opensearchdescription.xml" type="application/opensearchdescription+xml"/>
    
    </MTBlogResultHeader>
    <entry>
        <link rel="alternate" type="text/html" href="<$MTEntryPermalink encode_xml="1"$>"/>
        <title><$MTEntryTitle remove_html="1" encode_xml="1"$></title>
        <content type="text" xml:lang="<$MTBlogLanguage ietf="1"$>" xml:base="<$MTBlogURL encode_xml="1"$>"><$MTEntryExcerpt remove_html="1" encode_xml="1"$></content>
        <id><$MTEntryAtomID$></id>
        <published><$MTEntryDate utc="1" format="%Y-%m-%dT%H:%M:%SZ"$></published>
        <updated><$MTEntryModifiedDate utc="1" format="%Y-%m-%dT%H:%M:%SZ"$></updated>
    </entry>
    </MTSearchResults>
</feed>

They're probably not perfect, but I think they should work, once A9 gets upgraded to parse the 1.1 description and response formats. I couldn't find a way to get the search script to return different content types for different templates, so the Atom is served as text/html. Also the entry type for the response is text, but MT encloses some entries in CDATA blocks, which seems to confuse the feed validator.

Updated 2005-12-13 to match the latest OpenSearch specifications.