Thursday, August 25, 2005

Tech: Adding a new Search Engine programatically....

So you have a new cool google search appliance. Now you want a way for your users to be able to search easily from their Mozilla/Firefox browsers. The solution is to add your intranet search appliance as a new engine that will be available from both the sidebar and the menu bar. Programatically, this can be done using JavaScript by creating the following page:


<HTML><HEAD><TITLE>New Search Engine</TITLE></HEAD>
<BODY>

<script type="text/javascript">
<!--
function addEngine(name,ext,cat)
{
if ((typeof window.sidebar == "object") && (typeof
window.sidebar.addSearchEngine == "function"))
{
window.sidebar.addSearchEngine(
"http://googleapp.domain.com/"+name+".src",
"http://googleapp.domain.com/"+name+"."+ext,
name,
cat );
}
}
//-->
</script>
<a href="javascript:addEngine('EngineName','gif','Category')">Add Engine</a> (Google Appliance)

</BODY>
</HTML>



The src file and image will then be copied to the browser searchplugins folder. For
a Google Appliance, the contents of the src file might look like:



<search
version = "1.0"
name="EngineName"
description="EngineName Search"
method="GET"
action="http://googleapp.domain.com/search"
searchform="http://googleapp.domain.com/"
queryEncoding="UTF-8"
queryCharset="UTF-8"
>

<input name="le" value="en">
<input name="ie" value="UTF-8">
<input name="oe" value="utf-8">
<input name="q" user>
<input name="btnG" value="Google+Search">
<input name="site" value="MySheet">
<input name="client" value="Netli">
<input name="proxystylesheet" value="MySheet">
<input name="output" value="xml_no_dtd">
<input name="num" value="20">
<input name="sourceid" value="Mozilla-search">

# Finds results
<interpret
browserResultType="result"
resultListStart="<!--a-->"
resultListEnd="<!--z-->"
resultItemStart="<!--m-->"
resultItemEnd="<!--n-->"
>

# Finds Previous link
<interpret
browserResultType="result"
resultListStart=""
resultListEnd="d>"
resultItemStart=""
resultItemEnd=">

# Finds Next link
<interpret
browserResultType="result"
resultListStart="</a><td"
resultListEnd="</div><center>"
resultItemStart="nowrap>"
resultItemEnd="</table>"
>

</search>

<BROWSER
update="http://googleapp.domain.com/EngineName.src"
updateIcon="http://googleapp/EngineName.gif"
updateCheckDays="1"
>