JavaScript Site Search
There is not enough room here to show all the code of the search routine
so the description below is just the bare outline of the routine.
Arrays
The search works by scanning through an array of keywords in a JavaScript
file. There are in fact five parallel arrays defined as follows:
aHits = new Array();
aKeyWord = new Array();
aURL = new Array();
aSorted = new Array();
aTitle = new Array();
The FoxPro code which builds the site parses each HTML document and
pulls words from the Keyword and Description attributes to populate
the arrays. These are the array members for the current page:
aURL[87]='foxsearch.htm';
aTitle[87]='Search page for Alvechurch Data web site';
aKeyWord[87]='alvechurch, data, search, find, javascript';
aHits[87]=0;
Although the aTitle and aKeyword arrays are similar for many pages, they
have to be kept separate because the string comparison is case-sensitive
in JavaScript. The algorithm searches aKeyword but displays the equivalent
entry from aTitle.
Searching the Arrays
lcTarget = document.searchForm.searchFor.value.toLowerCase()
lnFound = 0
for (thisPage=1; thisPage < aKeyWord.length; thisPage++)
{
aHits[thisPage] = 0
}
laWords=lcTarget.split(" ")
for (lnWord = 0; lnWord < laWords.length; lnWord++)
{
for (thisPage=1; thisPage < aKeyWord.length;
thisPage++)
{
if(laWords[lnWord] == "")
{
}
else
{
if (aKeyWord[thisPage].indexOf(laWords[lnWord]) > -1)
{
aHits[thisPage]++;
if(aHits[thisPage]==1)
{
lnFound++;
}
}
}
}
}
if (lnFound==0)
{
writeResult(loPlaceHolder,
"No pages include '" + lcTarget + "'");
}
else
{
writeResult(loPlaceHolder, lnFound +
" pages found.");
showResults(loPlaceHolder, lnFound, lcTarget)
lnFound=0;
}
}
return false
|