|

Stand:
07.01.2004
| |
Site Search Engine for ACS-BURGER Homepage
<%
'Dimension global variables
Dim fsoObject 'File system object
Dim fldObject 'Folder object
Dim sarySearchWord 'Array to hold the words to be searched for
Dim blnIsRoot 'Boolean set to true if it is the root dirctory
Dim intNumFilesShown 'Holds the number of files shown so far
Dim intTotalFilesSearched 'Holds the number of files searched
Dim intTotalFilesFound 'Holds the total matching files found
Dim intFileNum 'Holds the file number
Dim intPageLinkLoopCounter 'Loop counter to display links to the other result pages
Dim sarySearchResults(200) 'Array holding the search results
Dim intDisplayResultsLoopCounter 'loop counter to diplay the results of the search
Dim intResultsArrayPosition 'Stores the array position of the array storing the results
Dim blnSearchResultsFound 'Set to true if search results are found
Dim strBarredFolders 'Holds the folders that you don't want searched
Dim strBarredFiles 'Holds the names of the files not to be searched
' -------------------------- Change the following line to the number of results you wish to have on each page ------------------------------------
Const intRecordsPerPage = 15 'cahnge this to the number of results to show on each page
' --------------------- Place the names of the folders you don't want searched in the following line spearated by commas --------------------------
strBarredFolders = "cgi_bin,_private" 'cgi_bin and _private have been put in here as examples, but you can put any folders in here
' ---------- Place the names of the files you don't want searched in the following line spearated by commas include the file extension -------------
strBarredFiles = "adminstation.htm,no_allowed.asp" 'adminstration.htm and not_allowed.asp have been put in as an examples
'-----------------------------------------------------------------------------------------------------------------------------------------------------
On Error resume Next
'Initalise variables
intTotalFilesSearched = 0
'Read in the search words to be searched
sarySearchWord = Split(Trim(Request.QueryString("search")), " ")
'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 Request.QueryString("search") = "" Then
'Get the path and the root folder to be searched
Set fldObject = fsoObject.GetFolder(Server.MapPath("./"))
'Set to true as this is searching the root directory
blnIsRoot = True
'Call the search sub prcedure
Call SearchFile
'Loop to search through the sub folders within the site
For Each fldObject In fldObject.SubFolders
'Check to make sure the folder about to be searched is not a barred folder if it is then don't search
If NOT InStr(1, strBarredFolders, fldObject.Name, vbTextCompare) > 0 Then
'Set to false as we are searching sub directories
blnIsRoot = False
'Call the search sub prcedure
Call SearchFile
End If
Next
'Reset server variables
Set fsoObject = Nothing
Set fldObject = Nothing
'Display the HTML table with the results status of the search or what type of search it is
Response.Write vbCrLf & " "
Response.Write vbCrLf & " "
'Display that there where no matching records found
If blnSearchResultsFound = False Then
Response.Write vbCrLf & " | Searched the site for " & Request.QueryString("search") & ". Sorry, no results found. | "
'Else Search went OK so display how many records found
Else
Response.Write vbCrLf & " Searched the site for " & Request.QueryString("search") & ". Displaying Results " & intFileNum + 1 & " - " & intNumFilesShown & " of " & intTotalFilesFound & ". | "
End If
'Close the HTML table with the search status
Response.Write vbCrLf & " "
Response.Write vbCrLf & " "
'HTML table to display the search results or an error if there are no results
Response.Write vbCrLf & " "
Response.Write vbCrLf & " "
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 - " & Request.QueryString("search") & " - did not match any files on this site."
Response.Write vbCrLf & "
"
Response.Write vbCrLf & " Suggestions:"
Response.Write vbCrLf & " "
Response.Write vbCrLf & " - Make sure all words are spelled correctly.
- Try different keywords.
- Try more general keywords.
- Try fewer keywords.
"
'Else display the results
Else
'Loop round to display each result within the search results array
For intDisplayResultsLoopCounter = 1 to (intNumFilesShown - intFileNum)
Response.Write vbCrLf & " "
Response.Write vbCrLf & " " & sarySearchResults(intDisplayResultsLoopCounter)
Response.Write vbCrLf & " "
Next
End If
'Close the HTML table displaying the results
Response.Write vbCrLf & " | "
Response.Write vbCrLf & " "
Response.Write vbCrLf & " "
End If
'Display an HTML table with links to the other search results
If intTotalFilesFound > intRecordsPerPage then
'Display an HTML table with links to the other search results
Response.Write vbCrLf & " "
Response.Write vbCrLf & " "
Response.Write vbCrLf & " "
Response.Write vbCrLf & " "
Response.Write vbCrLf & " "
Response.Write vbCrLf & " "
Response.Write vbCrLf & " | "
Response.Write vbCrLf & " Results Page: "
'If the page number is higher than page 1 then display a back link
If intNumFilesShown > intRecordsPerPage Then
Response.Write vbCrLf & " << Prev "
End If
'If there are more pages to display then display links to all the search results pages
If intTotalFilesFound > intRecordsPerPage Then
'Loop to diplay a hyper-link to each page in the search results
For intPageLinkLoopCounter = 1 to CInt((intTotalFilesFound / intRecordsPerPage) + 0.5)
'If the page to be linked to is the page displayed then don't make it a hyper-link
If intFileNum = (intPageLinkLoopCounter * intRecordsPerPage) - intRecordsPerPage Then
Response.Write vbCrLf & " " & intPageLinkLoopCounter
Else
Response.Write vbCrLf & " " & intPageLinkLoopCounter & " "
End If
Next
End If
'If it is Not the last of the search results than display a next link
If intTotalFilesFound > intNumFilesShown then
Response.Write vbCrLf & " Next >>"
End If
'Finsh HTML the table
Response.Write vbCrLf & " | "
Response.Write vbCrLf & " "
Response.Write vbCrLf & " "
Response.Write vbCrLf & " | "
Response.Write vbCrLf & " "
Response.Write vbCrLf & " "
End If
%>
| Searched <% = intTotalFilesSearched %> documents in total. |
|