JavaScript Search Facility for http://authors.aspalliance.com/brettb/default.asp

The following instructions describe how to add a JavaScript Search Facility to your website. To get the search facility running, the following are required:

How it Works

The Website Utility extracts all of the words from the website and finds the most relevant pages in the website for each word. Common English words (e.g. got, like, then) are removed, as are words of one or two characters in length. Word rankings depend on many factors, including their distribution through the entire website and their distribution in the content of a specific page.

The Website Utility creates a Search Data JavaScript File containing the rankings for each word and the most relevant pages for that word. It also creates the JavaScript required to parse the user's search query and find the most relevant pages matching their query.

Pages are sorted in search results according to their ranking for the particular word or words being searched for. The ranking scale goes from 0 to 99. Rank is higher for pages that most closely match the search term. In general, searching for words that are common on the site will produce search results with a lower rank than very specific words that occur on only one or two pages.

Important Note: For large websites, a client-side JavaScript search facility is obviously going to be inferior to one based on specialised server-based search software such using Active Server Pages (ASP) to search Microsoft's Index Server. Alternatively, you might like to consider using the ASP server-side Search Facility created by The Website Utility.

Search Form

The code for the search form is shown below:

Essential information: The search form needs a text box called TWUQuery. The form should use the GET method to submit to the search results page. To make it easier for users to search the website you might like to place the search form on all pages in the website.

Search Results

This page displays the search results. There is little JavaScript in this page as the main code is contained in the Code and Data JavaScript files. It is critical that these files are included in the search results page!

The code for the search results page is shown below:

Essential information: This page can of course be customised to fit in with the existing design of your website. If you want to display the search terms the user was searching for, then use this JavaScript code: <script language="JavaScript">document.write(TWU_OriginalSearchQuery);</script>. To display the search results, place this JavaScript code where you want the search results to appear: <script language="JavaScript">TWU_DisplaySearchResults(TWU_SearchQuery);</script>.

The search results page defines three JavaScript variables that can be used to change the output:

If you have a basic knowledge of JavaScript, it is also possible to change the display of the search results. This will involve editing the Search Code JavaScript file.

Search Code JavaScript File

This JavaScript file is required by the search results page. It contains the JavaScript functionality for finding pages matching the user's search query. The file has been placed in the output folder (output\) with the filename TWUSearchCode.js.

If you have a knowledge of JavaScript and want to change the way the search results are presented, then this file can be edited (be sure to take a backup first!). The JavaScript functions you may want to change are:

Search Data JavaScript File

This JavaScript file is also required by the search results page. You should not need to edit this file! The file has been placed in the output folder (output\) with the filename TWUSearchData.js.

Useful Tip: If you re-crawl a website to update the search facility, this is the only file that will have changed, so updating the search facility may be achieved by copying this file to the website.

Interesting Feature: The JavaScript Search Facility can be used on disk based websites (e.g. CDROMs). To do this the URLs in the TWU_URLs array would need to be truncated, so for example a URL http://www.foo.com/Services/Furnishings.htm should be changed to Services/Furnishings.htm

Reporting Main Page

Report generated by The Website Utility 2.8