下面代码可以全部复制粘贴到一个search.asp文件中,就能够实现静态页面的全文检索功能了。适合于页面数较少的站点,估计超过100个页面性能就很差了。

asp的站内搜索功能<%
asp的站内搜索功能Head 
= "站内搜索"
asp的站内搜索功能SearchString 
= Request("SearchString")
asp的站内搜索功能count
=0
asp的站内搜索功能
asp的站内搜索功能
'把当前目录的实际路径转换为虚拟路径
asp的站内搜索功能
Function UnMapPath( Path )
asp的站内搜索功能    UnMapPath 
= Replace(Mid(Path, Len(Server.MapPath("/")) + 1), """/")
asp的站内搜索功能
End Function
asp的站内搜索功能
asp的站内搜索功能
asp的站内搜索功能
Function SearchFile( f, s, title )
asp的站内搜索功能   
Set fo = fs.OpenTextFile(f)
asp的站内搜索功能   content 
= fo.ReadAll
asp的站内搜索功能   fo.Close
asp的站内搜索功能   SearchFile 
= InStr(1, content, S, vbTextCompare) > 0 
asp的站内搜索功能   
If SearchFile Then
asp的站内搜索功能      pos1 
= InStr(1, content, "<TITLE>", vbTextCompare)
asp的站内搜索功能      pos2 
= InStr(1, content, "</TITLE>", vbTextCompare)
asp的站内搜索功能      title 
= ""
asp的站内搜索功能      
If pos1 > 0 And pos2 > 0 Then
asp的站内搜索功能         title 
= Mid( content, pos1 + 7, pos2 - pos1 - 7 )
asp的站内搜索功能      
End If
asp的站内搜索功能   
End If
asp的站内搜索功能
End Function
asp的站内搜索功能
asp的站内搜索功能
Function FileLink( f, title )
asp的站内搜索功能   vPath 
= UnMapPath( f.Path )
asp的站内搜索功能   
If title = "" Then title = f.Name
asp的站内搜索功能   FileLink 
= "<A HREF=""" &  vPath & """>" & title & "</A>"
asp的站内搜索功能   FileLink 
= "<UL>·" & FileLink & "</UL>"
asp的站内搜索功能
End Function
asp的站内搜索功能
asp的站内搜索功能
Sub SearchFolder( fd, s ) 
asp的站内搜索功能   found 
= False  
asp的站内搜索功能   
For each f In fd.Files
asp的站内搜索功能      pos 
= InStrRev(f.Path, "." )
asp的站内搜索功能      
If pos > 0 Then
asp的站内搜索功能         ext 
= Mid(f.Path, pos + 1 )
asp的站内搜索功能      
Else
asp的站内搜索功能         ext 
= ""
asp的站内搜索功能      
End If
asp的站内搜索功能      
If LCase(ext) = "htm" Then
asp的站内搜索功能         
If SearchFile( f, s, title ) Then
asp的站内搜索功能            Response.Write FileLink(f, title)
asp的站内搜索功能            count
=count+1
asp的站内搜索功能            
' Response.Write cstr(count)
asp的站内搜索功能
         End If
asp的站内搜索功能      
End If
asp的站内搜索功能   
Next
asp的站内搜索功能
asp的站内搜索功能   
For each sfd In fd.SubFolders
asp的站内搜索功能      SearchFolder sfd, s
asp的站内搜索功能   
Next
asp的站内搜索功能
End Sub
asp的站内搜索功能%
>
asp的站内搜索功能
<html>
asp的站内搜索功能
asp的站内搜索功能
<head>
asp的站内搜索功能
<meta http-equiv="Content-Type" content="text/html; charset=gb_2312-80">
asp的站内搜索功能
<title><%=Head%></title>
asp的站内搜索功能
</head>
asp的站内搜索功能
asp的站内搜索功能
<body bgcolor="#FFFFFF">
asp的站内搜索功能
asp的站内搜索功能
<h1><%=Head%></h1>
asp的站内搜索功能
asp的站内搜索功能
<hr>
asp的站内搜索功能
asp的站内搜索功能
<!-- 注意search.asp为本文件,可根据需要修改!-->
asp的站内搜索功能
asp的站内搜索功能
<form action="search.asp" method="Get"> 
asp的站内搜索功能    
<p>请输入欲搜索的内容: <input type="text"
asp的站内搜索功能    size
="20" name="SearchString" value="<%=SearchString%>"> <input
asp的站内搜索功能    type
="submit" value="搜索"> </p>
asp的站内搜索功能
</form>
asp的站内搜索功能
<%
asp的站内搜索功能
Set fs = Server.CreateObject("Scripting.FileSystemObject")
asp的站内搜索功能
Set fd = fs.GetFolder( Server.MapPath("./") )   '设置开始搜索的路径(将遍历其所有子目录,当前设置为search.asp所在目录)!
asp的站内搜索功能

asp的站内搜索功能
If SearchString <> "" Then
asp的站内搜索功能   Response.Write 
"<H2>搜索<font color=red>" & SearchString & "</font>结果如下:</H2><P>"
asp的站内搜索功能   SearchFolder fd,SearchString
asp的站内搜索功能
End If
asp的站内搜索功能%
>
asp的站内搜索功能
<hr>
asp的站内搜索功能
</body>
asp的站内搜索功能
</html>
asp的站内搜索功能
asp的站内搜索功能
asp的站内搜索功能

相关文章: