Sunday, 24 February 2008

Google Reader Search Plugin for Firefox

Ok, another technical post, so those not interested can move right along. ;-)

A few days ago, I started learning about Search Engine plugin for Firefox as I was exploring ideas for searching functionality in a project I'm working on. Filled with curiosity,
I couldn't resist but look up the relevant documentation and build one myself.
It turns out, it is really easy (well, ok, relatively speaking, of course!) to build my own search engine.

The following is what I did to build a Google Reader search engine, but first, pre-requisites:
1) Need some understanding of HTML and Javascript. (minimal)
2) Need a web server (eg. Apache Httpd which I used).
3) Used the Firefox web browser before (Internet Explorer 7 should also work very similarly, but I have not tried it myself. If you feel brave, do try it yourself, and let me know how you went.)
4) A Google Reader Account (without this, you won't be able to use the search engine you'll have created by the end of this errr.. humble tutorial.)

To build Google Reader Search plugin:
1) Create a file named installer.html and save to a folder under web server's document root (eg. in my case, I saved it as: C:\servers\Apache2.2.6\htdocs\installer.html).
installer.html:
<html>
<head><title>Install a custom search engine</title></head>
<body>
<a href="#" onClick="window.external
.AddSearchProvider('http://localhost/googleReaderSearch.xml')">
Install Google Reader SearchEngine</a>
</body>
</html>

The key here is of course that one liner: onClick="window.external.AddSearchProvider('http://localhost/googleReaderSearch.xml')"
That will cause Firefox to install the search engine when you click on the link.

2) Create googleReaderSearch.xml which is essentially a description file that tells the Firefox what to do.

Save it in document root of your web server next to your installer.html.
googleReaderSearch.xml:
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"
xmlns:moz="http://www.mozilla.org/2006/browser/search/">
<ShortName>Google Reader</ShortName>
<Description>Search for items in your Google Reader</Description>
<Tags>internet web search rss atom reader google</Tags>
<Image height="16" width="16" type="image/x-icon">http://www.google.com/reader/ui/favicon.ico</Image>
<Url type="text/html" method="GET" template="http://www.google.com/reader/view/#search/{searchTerms}/"/>
<InputEncoding>UTF-8</InputEncoding>
<AdultContent>false</AdultContent>
</OpenSearchDescription>


3) Start up your web server if it's not running already, and browse to http://localhost/installer.html

4) Click on the link and install it. That's it!

Of course, the meaty part is the step 2.

I was actually going to upload to Mozilla site if it wasn't available, but it was already there.

references:
a) Creating OpenSearch Plugins for Firefox
b) OpenSearch.org

Update (24-Feb-2008): Added some links which should've been included in the first place.

No comments: