You knew that it would only be a matter of time before some one would take our favorite scripting language, JavaScript, and try to build one of the most complex creations in computer science, a search engine. Andrew Taylor was browsing a certain company's website and noticed that their search function was wholly useless, but seemed to return results incredibly quickly, without even reshing the page. Curious as to what this might be, Andrew did a quick View Source and uncovered the JavaScript Search Engine ...

searchItems = new Array();

searchItems[0] = new Array
 ( "Initech Solutions :: Home",
   "index.htm",
   "The home page for Initech Solutions.",
   new Array (
     "home","initech","first","intro","introduction",
     "top","open","index","main","start")
 );

searchItems[1] = new Array
 ( "Initech Solutions :: Contact Sales",
   "contact_sales.htm",
   "For any questions regarding our products and services,"
   + " please use this form to contact our sales staff.",
   new Array (
     "contact","sales","information","sales","help",
     "assistance","people","question","questions")
 );

/* Snipped search conditions */

searchItems[46] = new Array
 ( "Products :: TPS Manager",
   "products/tps_manager.htm",
   "If you have been overwhelemed by TPS requirements,"
   + " you may find TPS Manager a nice addition to your "
   + " product suite.",
   new Array (
     "product","products","tps","reports",
     "report","information","manager")
 );

searchItems[47] = new Array
 ( "Services :: NMP Compliance",
   "services/nmp_comp.htm",
   "With ever changing NMP regulations, it's vital to"
   + " keep up to date with guidelines. Click here to"
   + " find out how.",
   new Array (
     "service","services","audit","iso-667","compliance",
     "factory","pooling","location","audits","iso","667")
 );


function SiteSearch(srch)
{

  words = srch.split(" ");
  results = new Array();

  for (i=0; i<searchItems.length; i++)
  for (j=0; j<searchItems[i][3].length; j++)
  for (k=0; k<words.length; k++)
    if (searchItems[i][3][j] == words[k].toLowerCase())
      results[results.length] = 
        new Array
          ( searchItems[i][0], 
            searchItems[i][1],
            searchItems[i][2]);

  resultText = "";
  if (!results.length)
    resultText = "No results found. Please try different key words.";

  else
    for (i=0; i<results.length; i++)
      resultText = 
        "<a href='/" + results[i][1] + "'>" + results[i][0] + "</a>"
        + "<br>"
        + results[i][2]
        + "<br><br>";

  document.getElementById("searchResults").innerHTML = resultText;

  alert("Search Complete.");
}

(Note that all identifying information has been changed to protect the innocent/guilty)

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!