Wednesday, November 21, 2007

open search - search from modern browser panel

So you are working on Internet shop like me? And you want to improve it as much as you can?:) OK I am doing the same, because I like my work.

Ok you probably use new and modern browser like Firefox 2 or Internet Explorer 7, and you already noticed and get used to use integrated search field (usually in upper right corner of your window). You probably have Google, Yahoo, eBay and wikipedia in it or more of them for different needs. So if you do something from last two sentences you should noticed thats very nice feature (probably as nice as tabbed browsing). You can create search engine for you own website and add it to the list of engines. It's incredibly simple by using "openSearch" format.

One way of making it is to go to your firefox system catalog C:\Program Files\Mozilla Firefox\searchplugins (in my windows system) here you will see your already installed search engines. Open one of them as XML file (it actually is not more then it) and look at what you see. It looks something like this:

<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"
xmlns:moz="http://www.mozilla.org/2006/browser/search/">
<ShortName>engineName</ShortName>
<Description>engineDescription</Description>
<InputEncoding>inputEncoding</InputEncoding>
<Image width="16" height="16">data:image/x-icon;base64,imageData</Image>

<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>
</OpenSearchDescription>


I think it pretty self explaining, but its probably because I've already made one for my company shop :)
I will skip explanation of ShortName and Description it's easy to understand.
InputEncoding is encoding used by your website, if you use UTF-8, it will be UTF-8
Image is your website icon encoded in Base-64 (one of first tools for encoding base64 I found: http://www.motobit.com/util/base64-decoder-encoder.asp) I personally used PHP integrated function for that.
method is method used in your website search form (GET or POST) GET preferred, because it's the only one which works in IE7 and we love cross browser compatibility, don't we?
searchURL is address for search request in your website insert {searchTerms} variable in your URL where needed
you can set more parameters by ParamName1 and ParamValue1 which will be send then user hit Enter.
SearchFormUrl should be your website address...
So I think our search engine engine work now, you can try it by saving it to searchengines directory and restarting Firefox. You can test it and fix any bugs you found, if you still face same problems here you will find more help

Now then you have your website with new feature you can make it easier to discover.

If you visit www.php.net you will notice autodiscovery feature working:

the blue mark on FF and orange on IE7 means website you are visiting have search engine which can be installed on your browser. This is made quite simple - you just need to add one line in head of your website:
<link rel="search" type="application/opensearchdescription+xml" title="searchTitle" href="pluginURL">
searchTitle should be the same as the one in freshly your created plugin
pluginURL is URL to this plugin XML file on you website

Thats it, you have new cool and usefull feature on your website ;)

No comments: