May 22, 2012

Create an installable search plugin for your blog

An installable search engine is a search function on a site that can be accessed directly from the browser without visiting the website itself. The search engine is formatted using the opensearch description document which gives it the ability to be discovered and used by various search client applications.

I really did not think too much of this during the days when I used to use Firefox primarily. As I began to use the new browser, Flock, notion of installable search engine took more prominence.

Creating an opensearch description file for a site’s search engine is quite easy and is well documented at the OpenSearch website. There are two steps to this.

  1. Using the OpenSearch description format, create an XML file that describes the search engine
  2. Provide a link to this XML document in the HEAD section of the website.


Creating the Opensearch description XML file

The following is the template for the OpenSearch description file (from the OpenSearch website).


<OpenSearchDescription xmlns="http://www.opensearch.org/Specifications/OpenSearch/1.1">
                       xmlns:moz="http://www.mozilla.org/2006/browser/search/"&gt;
<ShortName>engineName</ShortName>
<Description>engineDescription</Description>
<InputEncoding>inputEncoding</InputEncoding>
<img height="16" width="16" />data:image/x-icon;base64,imageData
<Url type="text/html" method="method" template="searchURL">
  <param name="paramName1" value="paramValue1">
  ...
  <param name="paramNameN" value="paramValueN">
</Url>
<Url type="application/x-suggestions+json" template="suggestionURL">
<moz:SearchForm>searchFormURL</moz:SearchForm>
</Url>
</OpenSearchDescription>

Let us now try to generate a opensearch description format file that is specific to this website (http://rajeev.name)


<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
        <ShortName>rajeev.name</ShortName>
        <Description>Search Form for The Occasional Blog</Description>
        <Contact>http://xri.net/=rajeev/(+contact)/</Contact>
        <Tags>Search Rajeev Karamchedu Occasional Technology Unix Storage NFS iSCSI Sysadmin Identity</Tags>
        <Contact>rajeev@hotmail.com</Contact>
        <Url    type="text/html"
                                method="get"
                                template="http://rajeev.name/blog/?s={searchTerms}"/>
        <Image height="16" width="16" type="image/x-icon">http://rajeev.name/blog/favicon.ico</Image>
        <AdultContent>false</AdultContent>
        <Language>en-us</Language>
        <Attribution>Search data Copyright 2007, Rajeev Karamchedu., All Rights Reserved </Attribution>
        <SyndicationRight>open</SyndicationRight>
</OpenSearchDescription>

Save this XML to a web-enabled location. In my case, I am saving this to a file called osd.xml. It can be directly accessed here.

Enabling Auto-Discovery

In order for browsers like Flock and Firefox to auto discover this search engine, simply add one line to the <head> section of the website.

<link rel="search" type="application/opensearchdescription+xml" title="The Occasional Blog Search" href="http://rajeev.name/osd.xml">

These two steps are the only ones needed to make your search engine visible to Firefox and flock. This is how Flock lets you know that this site has an installable search engine ! Cool!!

Comments

  1. If you are using Flock and if something is not quite right with the XML file, then the drop down list of the available search engines will be disabled.

    In that case, know that each search engine description is stored in a separate file in the Flock Profile subdirectory (searchplugins). Remove the file that has your site plugin info and restart Flock – All should be good to go for troubleshooting !

Speak Your Mind

*