Designing your own search engine for a site has, until recently, been fiendishly difficult, involving no small amount of skill in scripting languages or creating databases. To be honest, a fully-customised, searchable database still requires considerable ability, and I'll probably look at your options for creating such a search engine in MySQL some time in the near future.
In the meantime, the Web provides a number of alternatives in the form of ready-made scripts or third-party resources that are easier to adapt.
Perl and simple searches
If you have access to the cgi-bin on your Web site, one tried-and-trusted way to set up a search engine is using a Perl script which is very competent at ploughing through Web pages looking for text.
There are plenty of Perl-based Web searches available online, the most widely used being Simple Search (www.scriptarchive.com/search.html). Here, because it is slightly easier to set up (and it's got a great name), we'll be using Jason Anthony's Jasearch (www.ufbs.co.uk/jason/perl/jasearch.html) - see screen shot.
Jasearch has two components, the HTML search form and a script engine, jasearch.pl. This script is particularly easy to set up because it will probably require no modification at all - so long as your first line points to the appropriate location of Perl (for example, #!/usr/bin/perl) as all variables are set up in your Web page.
After you've loaded jasearch.pl to an appropriate cgi-bin directory on your server, you create a Web form that includes the following code:
< form method="post" action="cgi-bin\jasearch.pl" > < input type="hidden" name="base" value="../yourdirectory" > < input type="hidden" name="rbase" value="http://www.yoursite.com" > Search for < input type="text" name="sv" value="" > < input type="submit" value="Search" > < input type="reset" value="Reset" > < /form >
Back to base
You will be able to add these buttons and fields in pretty much any Web editor, but the values for the various hidden and text fields (base, rbase and sv) are important.
Base indicates the directory you want to search on your server, while rbase provides the URL. The name sv for the text search box is the standard variable used within jasearch.pl itself - while it is possible to change this, you will then need to modify the perl script. With the code in place as listed above, any words entered into your text field sv will be posted to the Jasearch Perl script and results returned to a pre-created search results page.
Within the jasearch.pl script, you'll find the parameters to modify the format of this page. Of course, you should adapt your initial search form to match the look and feel of your site.
Perl was designed to work with text documents and has the advantage of being supported across many Web sites, but if you don't have access to a cgi-bin folder it can be impossible to implement.
The X factor
Of the flat-file database searches, one good source is XSearch 5.2: this was developed by Dynamic Core, although it doesn't appear to offer support for it any longer, and the original Web site has been closed (www.dynamic-core.net). A search in Google will turn up plenty of sites where you can download the code - including the all-important db.js files - and an editor is also available at http://xseditor.free.fr to help take some of the tedium out of creating your database. Of course, you could just head to the cover disc instead.
If you want a world-class search engine, it's also worth bearing in mind that Google has started making available its API (application programming interface). The service is still in beta and restricted to 1000 searches a day - and you'll need some skills to integrate it into your site via XML - but it offers enormous potential. For more information, go to www.google.co.uk/apis.
Sites OF THE MONTH While not dedicated to search engines per se, you will find customisable scripts for these as well as nearly 6000 others at ScriptSearch (www.scriptsearch.com). Quantity itself is no guarantee of quality, but there are some great Web widgets available here, whether you need a free subscription manager, shopping cart scripts or remotely hosted bulletin boards. Scripts are available in a wide range of languages, including ASP, Flash and Python as well as Perl and PHP.
Add hassle-free searches with FreeFind
If you want to create a search engine with the minimum of programming - and cost - another alternative is to use a remotely hosted engine such as that provided by FreeFind (details at www.freefind.com). Once you've registered the details of your site and a username/current e-mail, log on to the control centre at control.freefind.com to use FreeFind to generate a search engine for your site.
This process consists of two parts: first of all, you need to generate an index of your site by clicking on the Build Index tab. You can schedule this to take place at a certain time, or click the Index now link - it may take up to 24 hours to complete. You can also specify advanced options such as whether to index PDFs or exclude certain areas.
After your site has been indexed, click on the HTML tab to create the code you need to access the search engine. Simply copy and paste the HTML provided to create a simple search box and button that you can then customise in your favourite Web editor.