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.

Comments

the new opensearch namespace contains 'opensearchresponse', not 'opensearchrss'

also, is the opensearch response template different than the regular movable type atom search result? Seems to me it should be one-and-the-same.

Also, how about adding the opensearch description autodiscovery <link /> tag to the head of all pages (mime type 'application/opensearchdescription+xml')?

nice work :-)

Fixed the namespace, thanks.

Is there an Atom search result template? I might have missed that file when I upgraded - that would certainly make things easier.

Not sure about adding the autodiscovery link to all pages, but I will add it to the index page.

not on all pages? hmn. well, yes, the index page. i suppose category pages could have their own opensearches. any other reasons why not to have it on every page?

as to MT templates, I've no idea since I've only used wordpress

I decided that individual pages should only have links that relate specifically to that page; links that relate to the whole site should be on the main index page.

Is there a Wordpress Atom search result template?

I'm pretty sure there is.. will look into it when I'm at home. Actually I think the files are all online somewhere...

I see you're using rel="opensearch"

Personally I think "search" or "search-description" makes more sense, since the MIME type can give the specific type of search or search description. Further thoughts?

Also, how about linking to the opensearch description from within rss/atom.. what should the rel be? Interesting that atom:link doesn't (yet) support the 'rev' attribute.

I took the link rel="opensearch" (and some of the other code) from http://www.snellspace.com/wp/?p=230 (I see he has a nice XSLT for the description file too).

Using rel="search-description" might make more sense, you're right, as long as each possible search description format uses a different MIME type.

From within Atom, I'd imagine the link would be just the same as in HTML.

All fields are optional, email address will not be shown; no HTML, URLs are automatically hyperlinked.