DentedReality

JavaScript Search Engine

This is a very simple search engine which is written entirely in JavaScript. There are advantages as well as disadvantages to this approach, and I've listed a couple of them below.

Advantages

  1. Can be used anywhere! Copy your site (along with its search engine) onto a CD-ROM and it can still operate.
  2. Very fast for smaller search databases
  3. Simple to implement and doesn't have any special software requirements on your server/host.

Disadvantages

  1. Not very powerful - it only uses very basic keyword matching
  2. No full-text indexing or anything like that, only works on the keywords in the JavaScript-array database :)
  3. Manual indexing required! You will need to either manually enter the details of all the pages you want to be available in your search engine, or devise some sort of automated system to produce the JavaScript "database" file required for the search engine to operate
  4. Gets very slow with large databases of pages.

So Why Bother?

Why would I write something like this? Actually because it was specifically required for a CD-ROM-based website that I was developing, which needed at least a basic search capability. Turns out that it worked very well and received some good feedback.

By producing the whole thing in JavaScript, I was able to implement a completely portable, very lightweight search engine.

Hope you can find a good use for this one - I know it really did "hit the spot" when I needed it!

How Do I Use It?

First up, sort out how you are going to populate "searchDB.js" with the details of all your pages. You should notice that the file is just a series of JavaScript statements which create search entries, according to this format (make sure you increment "x" each entry);

searchDB[x] = new searchOption("PageTitle", "KeywordsWithCommas", "PageDescription", "URL");

Once that's sorted out, you need to set up a form which has a text field with the name "searchTxt". That field should be in a form with the method="GET" and the "action" set to the page where you want your results displayed (say search.html)

On search.html, you need to include both the searchDB.js and searchEngine.js files something like this;

<html>
<head>
<title>Search Example</title>
<script language="JavaScript1.2" src="searchEngine.js"></script>
<script language="JavaScript1.2" src="searchDB.js"></script>
</head>

Then, in the body of that page somewhere, you should basically copy and paste the example code from "snippet.js" and use that as a foundation for formatting the results.

About Dented Reality

Dented Reality actually specialises in Usability, Information Architecture and database development, but produces a number of PHP and JavaScript-based projects 'on-the-side'. If you enjoy or are benefitting from this project, you can make a donation on the Dented Reality website, although it is not required. If you like this project, please let me know that I am doing something right!

JS Search

Since there is not a lot of documentation available for this project yet, use it at your own risk! :)