Zanettiland Site Search Engine
<% 'Read in all the search words into one variable strSearchWords = Trim(Request.QueryString("search")) 'If the site is in English then use the server HTML encode method If blnEnglishLanguage = True Then 'Replace any HTML tags with the HTML codes for the same characters (stops people entering HTML tags) strSearchWords = Server.HTMLEncode(strSearchWords) 'If the site is not english just change the script tags Else 'Just replace the script tag <> with HTML encoded < and > strSearchWords = Replace(strSearchWords, "<", "<", 1, -1, 1) strSearchWords = Replace(strSearchWords, ">", ">", 1, -1, 1) End If 'Slit each word to be searched up and place in an array sarySearchWord = Split(Trim(strSearchWords), " ") 'Read the file number to show from intFileNum = CInt(Request.QueryString("FileNumPosition")) 'Set the number of files shown so far to the file number read in above intNumFilesShown = intFileNum 'Create the file system object Set fsoObject = Server.CreateObject("Scripting.FileSystemObject") 'If there is no words entered by the user to search for then dont carryout the file search routine If NOT strSearchWords = "" Then 'Get the path and the root folder to be searched Set fldObject = fsoObject.GetFolder(Server.MapPath("./")) 'Read in the server path to this ASP script strServerPath = fldObject.Path & "\" 'Set to true as this is searching the root directory blnIsRoot = True 'Call the search sub prcedure Call SearchFile(fldObject) 'Reset server variables Set fsoObject = Nothing Set fldObject = Nothing 'Call the Bubble Sort procedure to sort the results into highest matches first Call SortResultsByNumMatches(sarySearchResults, intTotalFilesFound) 'Display the HTML table with the results status of the search or what type of search it is Response.Write vbCrLf & "| Searched the site for " & strSearchWords & ". Sorry, no results found. | " 'Else Search went OK so display how many records found Else Response.Write vbCrLf & "Searched the site for " & strSearchWords & ". Displaying Results " & intFileNum + 1 & " - " & intNumFilesShown & " of " & intTotalFilesFound & ". | " End If 'Close the HTML table with the search status Response.Write vbCrLf & "
| "
'If no results are found then display an error message
If blnSearchResultsFound = False Then
'Write HTML displaying the error
Response.Write vbCrLf & " " Response.Write vbCrLf & " Your Search - " & strSearchWords & " - did not match any files on this site." Response.Write vbCrLf & " " Response.Write vbCrLf & " Suggestions:" Response.Write vbCrLf & " " Response.Write vbCrLf & "
" Response.Write vbCrLf & " " & sarySearchResults(intDisplayResultsLoopCounter,1) Response.Write vbCrLf & " " Next End If Response.Write vbCrLf & " " 'Close the HTML table displaying the results Response.Write vbCrLf & " | "
Response.Write vbCrLf & "
" Response.Write vbCrLf & "
"
Response.Write vbCrLf & "
| "
Response.Write vbCrLf & "
| Searched <% = intTotalFilesSearched %> documents in total. |
