Site Search Engine for ACS-BURGER Homepage
" Response.Write vbCrLf & "
% 'Sub procedure to do the search Public Sub SearchFile 'Dimension local variabales Dim filObject 'File object Dim tsObject 'Text stream object Dim RegExpObject 'RegExp Object Dim strFileContents 'Holds the contents of the file being searched Dim strPageTitle 'Holds the title of the page Dim intTitleStartPositionInFile 'Holds the start postion in the file being searched of the title Dim intTitleEndPositionInFile 'Holds the end postion in the file being searched of the title Dim strPageDescription 'Holds the description of the page Dim intDescriptionStartPositionInFile 'Holds the start postion in the file being searched of the description Dim intDescriptionEndPositionInFile 'Holds the end postion in the file being searched of the description Dim intSearchLoopCounter 'Loop counter to search all the words in the array Dim strSearchWords 'Holds the search words Dim blnSearchFound 'Set to true if the search words are found On Error resume Next 'Loop to search each file in the folder For Each filObject in fldObject.Files 'Check the file extension to make sure the file is an html or asp file If Right(filObject.Name, 4) = ".htm" Or Right(filObject.Name, 5) = ".html" Or Right(filObject.Name, 4) = ".asp" Then 'Check to make sure the file about to be searched is not a barred file if it is don't search the file If NOT InStr(1, strBarredFiles, filObject.Name, vbTextCompare) > 0 Then 'Open the file for searching Set tsObject = filObject.OpenAsTextStream 'Read in the contents of the file strFileContents = tsObject.ReadAll 'Initalise the search found variable to flase blnSearchFound = False 'If the user has choosen to search by phrase If Request.QueryString("mode") = "phrase" Then 'Read in all the search words into one variable strSearchWords = Trim(Request.QueryString("search")) 'Search the file for the phrase If InStr(1, LCase(strFileContents), LCase(strSearchWords), 1) then 'If the search is found then set the search found variable to true blnSearchFound = True End If 'Else the search is either by all or any words Else 'If the search is by all words then initialise the search found variable to true If Request.QueryString("mode") = "allwords" then blnSearchFound = True 'Loop round to search for each word to be searched For intSearchLoopCounter = 0 to UBound(sarySearchWord) 'Search the file for the search words If InStr(1, LCase(strFileContents), LCase(sarySearchWord(intSearchLoopCounter)), 1) Then 'If the search word is found and the search is for any words then set the search found variable to true If Request.QueryString("mode") = "anywords" then blnSearchFound = True Else 'If the search word is not found and the search is for all words then set the search found variable back to false as one of the words has not been found If Request.QueryString("mode") = "allwords" then blnSearchFound = False End If Next End If 'Calculate the total files searched intTotalFilesSearched = intTotalFilesSearched + 1 'If the search found variable is true then display the results If blnSearchFound = True Then 'Calculate the total files found intTotalFilesFound = intTotalFilesFound + 1 'Check that the file shown is between the the files shown so far and the maximum files to show per page If intNumFilesShown < (intRecordsPerPage + intFileNum) and intTotalFilesFound > intNumFilesShown Then 'Calculate the number of results shown intNumFilesShown = intNumFilesShown + 1 'Read in the title of the file 'Get the position in the file of the HTML tag
'Read in the page title of the file by removing eveything before and after the title HTML tags
strPageTitle = Trim(Mid(strFileContents, intTitleStartPositionInFile, (intTitleEndPositionInFile - intTitleStartPositionInFile)))
'If there is no pag title then give the pag title variable the value No Title
strPageTitle = "No Title"
'Read in the description of the file
'Get the start position in the file of the description
intDescriptionStartPositionInFile = InStr(1, strFileContents, "", 1)
'Read in the descrition from the file
strPageDescription = Trim(Mid(strFileContents, intDescriptionStartPositionInFile, (intDescriptionEndPositionInFile - intDescriptionStartPositionInFile)))
'If the is no description then the description variable will hold the appropriate message
strPageDescription = "There is no description available for this page"
'Place the search results into the saerch results array
'Calculate the array position of the results array
intResultsArrayPosition = intResultsArrayPosition + 1
'Set the search results found boolean to true
blnSearchResultsFound = True
'If the file is in the root directory then
If blnIsRoot = True Then
'Place the search results into the search results array
sarySearchResults(intResultsArrayPosition) = "" & strPageTitle & "
" & vbCrLf & " " & strPageDescription 'Else it is not in the root directiory Else 'Place the search results into the search results array sarySearchResults(intResultsArrayPosition) = "" & strPageTitle & "
" & vbCrLf & " " & strPageDescription End If End If End If 'Close the text stream object tsObject.Close End If End If Next 'Reset server variables Set filObject = Nothing Set tsObject = Nothing End Sub %>