Error 

Build a Custom Search Engine Plugin

1,837 views
Posted July 20, 2006 at 06:07am in Computers, Programming

Everyday I find myself returning to various websites repeatedly to find a simple fix or two words I cant remember to put in code. To fix this I have started using custom Firefox search plugins, which I have also made availabe for this site. It is extremely simple to make and it will save you from waiting for their page to load and then navigating to their search page.

To start us off open your favorite text editor and enter the following in your comment header.

# Mozilla/Netscape 6+ plugin for DIGITAL39.com
# by Peter Manis<contact.39@gmail.com>
#
# Created: July 2, 2006
# Last updated: July 20, 2006
#

This is always the first line in your engine and simply states it is a search engine.

<search

The next step is to enter the version. Mozilla says this is the version of Netscape it was supposed to be tested with.

version="7.1"

Next, add your plugin name and description

name="DIGITAL39 Search"
description="Search DIGITAL39.com for Information"

This next line tells Firefox what page we send the information to. This is defined with the “action” attribute of the form tag found on the page you use to search the site you are building this for. In my case it “/index.php” so I would enter

action="http://www.digital39.com/index.php"

or simply

action="http://www.digital39.com/"

Now we enter in the location of the search form, which again is “/index.php” in my case

searchForm="http://www.digital39.com/index.php"

It will be nice when we can use the POST method, but for now GET is only supported

method="GET"

and close it up with

>

On the next line we want to let webmasters know that Mozilla search is being used to search the site.

<input name="sourceid" value="Mozilla-search">

The next line is very important, it specifies the user input. To get this value look at the query string appended to your search page. The words you entered should follow some sort of identifier. For my site it is “index.php?s=words” This simply says that I searched for “words” So referencing my site ’s’ is what we would enter in, for google it is a ‘q’ it will vary from site to site.

<input name="query" user>

The INTERPRET tag tells the engine how to handle the results. Refer to quickstart for more information.

<interpret
browserResultType="result"
resultListStart="<!-- RESULT LIST START -->"
resultListEnd="<!-- RESULT LIST END -->"
resultItemStart="<!-- RESULT ITEM START -->"
resultItemEnd="<!-- RESULT ITEM END -->"
>

The last section of our search engine defines the update parameters.

<browser
update="http://static.digital39.com/search/search39.src"
updateIcon="http://static.digital39.com/search/search39.gif"
updateCheckDays="7"
>

This tells our browser to check www.digital39.com every 7 days for an updated version of the search engine and use the updateIcon for the engine icon. To finish it up save the file with a .src extension.

To install these search engines you have two choices, you can install them off the server like on my site or you can install them manually. To have them install from your site add the following code to your website. Change the location of the files from digital39.com to the location of your choice.

<script type="text/javascript">
<!--
function errorMsg()
{
  alert("Netscape 6 or Mozilla is for sherlock plugins");
}
function addEngine(name,ext,cat,type)
{
  if ((typeof window.sidebar == "object") && (typeof
  window.sidebar.addSearchEngine == "function"))
  {
    //cat="Web";
    //cat=prompt("Category to Install Engine","Web")
    window.sidebar.addSearchEngine(
      "http://static.digital39.com/search/"+name+".src",
      "http://static.digital39.com/search/"+name+"."+ext,
      name,
      cat );
  }
  else
  {
    errorMsg();
  }
}
//-->
</script>

and then put this link somewhere, of course you will need to edit this accordingly

<a href="javascript:addEngine('search39','gif','Web',0)">Firefox Search Engine</a>

If you prefer to install the search engines manually, here are some standard locations for Firefox. I can only be sure of Windows because I never use a Mac, and I don’t really use Linux for browsing. Just simply copy the .src file to that directory along with the icon.

Linux
/usr/lib/Firefox/searchplugins

Windows
C:\Program Files\Mozilla Firefox\searchplugins

Mac
/Mozilla/searchplugins/

You have now created your very own Firefox search engine. I have listed some resources below. Here is the source from my search engine

[1] Huge Respository of Search Engines
[2] Search Engine Generator
[3] Documentation

  • Google
  • del.icio.us
  • Digg
  • Spurl
  • Facebook


Leave a Reply