Below Code You can copy and paste all the files to a search. asp file to achieve full-text retrieval of static pages. Suitable for websites with few pages, it is estimated that the performance of over 100 pages is poor.
< %
Head = " Intra-Site Search "
Searchstring = Request ( " Searchstring " )
Count = 0
' Convert the actual path of the current directory to a virtual path
Function Unmappath (PATH)
Unmappath = Replace ( Mid (Path, Len (Server. mappath ( " / " )) + 1 ), "" , " / " )
End Function
Function Searchfile (F, S, title)
Set Fo = FS. opentextfile (f)
Content = Fo. readall
Fo. Close
Searchfile = Instr ( 1 , Content, S, vbtextcompare) > 0
If Searchfile Then
Pos1 = Instr ( 1 , Content, " <Title> " , Vbtextcompare)
Pos2 = Instr ( 1 , Content, " </Title> " , Vbtextcompare)
Title = ""
If Pos1 > 0 And Pos2 > 0 Then
Title = Mid (Content, pos1 + 7 , Pos2 - Pos1 - 7 )
End If
End If
End Function
Function Filelink (F, title)
Vpath = Unmappath (F. Path)
If Title = "" Then Title = F. Name
Filelink = " <A href = "" " & Vpath & " ""> " & Title & " </A> "
Filelink = " <Ul> · " & Filelink & " </Ul> "
End Function
Sub Searchfolder (FD, S)
Found = False
For Each F In FD. Files
Pos = Rev (F. path, " . " )
If Pos > 0 Then
EXT = Mid (F. Path, POS + 1 )
Else
EXT = ""
End If
If Lcase (EXT) = " Htm " Then
If Searchfile (F, S, title) Then
Response. Write filelink (F, title)
Count = Count + 1
' Response. Write CSTR (count)
End If
End If
Next
For Each SFD in FD. subfolders
Searchfolder SFD, S
Next
End sub
% >
< Html >
< Head >
< Meta HTTP - Equiv = " Content-Type " Content = " Text/html; charsets = gb_2312-80 " >
< Title > < % = Head % > </ Title >
</ Head >
< Body bgcolor = " # Ffffff " >
< H1 > < % = Head % > </ H1 >
< HR >
< ! -- Note that search. asp is the file and can be modified as needed! -->
< Form Action = " Search. asp " Method = " Get " >
< P > Enter the content to search: < Input type = " Text "
Size = " 20 " Name = " Searchstring " Value = " <% = Searchstring %> " > < Input
Type = " Submit " Value = " Search " > </ P >
</ Form >
< %
Set FS = Server. Createobject ( " Scripting. FileSystemObject " )
Set FD = FS. getfolder (server. mappath ( " ./ " )) ' Set the start search path (all its subdirectories will be traversed and the current directory is search. asp )!
If Searchstring <> "" Then
Response. Write " <H2> Search <font color = Red> " & Searchstring & " </Font> result: </H2> <p> "
Searchfolder FD, searchstring
End If
% >
< HR >
</ Body >
</ Html >