How to let Google detect a site search engine?
When I implemented a search function for my online Klingon dictionary, I found that I didn't need an OpenSearch description for Chrome to autodetect it as a search engine.
NOTE: While this is a simpler method, it does not allow for advanced features like specifying a search template, a custom favicon (Chrome automatically uses the favicon of the site) etc. It also might not work for other browsers than Chrome.
I started off with the instructions here Search Engine Autodiscovery: Google Chrome Autodiscovery, which say:
Interestingly the auto discovery only works if the search engine is at the homepage. You have to have either an input field of the type
search
or of the typetext
with the names
:<form> <input type="search" name="s" /> </form>
or
<form> <input type="text" name="s" /> </form>
I got Chrome to autodetect the search engine on my website klingonska.org without using an OpenSearch description.
However I deviated from the above description, as I found I didn't need have to have field called s
nor use type="search"
. My final <form>
look something like this (in reduced form).
<form method=get action="dict/">
<input name=q placeholder="Search dictionary…">
<button type=submit>Search</button>
</form>
The cruicial factors seemed to be that the form was located on the root page http://<domain>/
page (not a subpage like http://<domain>/<dir>/<something>.html
). And, IIRC, that the search form contain only a single field.
After a little digging I found this page that describes this. Also you can read in Stackoverflow's source code and find this line of code:
<link rel="search" type="application/opensearchdescription+xml" title="Stack Overflow" href="/opensearch.xml">
What it does is indicate to Google that the description for how to use your search engine in the file /opensearch.xml
which contains this:
<?xml version="1.0" encoding="UTF-8" ?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/">
<ShortName>Stack Overflow</ShortName>
<Description>Search Stack Overflow: Q&A for professional and enthusiast programmers</Description>
<InputEncoding>UTF-8</InputEncoding>
<Image width="16" height="16" type="image/x-icon">http://sstatic.net/stackoverflow/img/favicon.ico</Image>
<Url type="text/html" method="get" template="http://stackoverflow.com/search?q={searchTerms}"></Url>
</OpenSearchDescription>