-
您的位置:首页 → 精文荟萃 → 软件资讯 → 用ASP做一个TOP COOL的站内搜索
用ASP做一个TOP COOL的站内搜索
时间:2004/10/7 19:08:00来源:本站整理作者:蓝点我要评论(2)
-
该搜索引擎由一个HTM文件一个ASP文件组成,主要是运用FILESYSTEMOBJECT组件来达到目的,功能强大,修改界面以后可以直接拿来使用,当然加上一点自己的东西就更加好了。
searchpage.htm
该HTM文件用来传入条件
ASP搜索引擎范例
-
------------------------------------------------------------------------
显示结果的ASP程序
search.asp
'<%=Request("SearchText")%>'的搜索结果
'<%=Request("SearchText")%>'的搜索结果
<%
Const fsoForReading = 1
Dim objFile, objFolder, objSubFolder, objTextStream
Dim bolCase, bolFileFound, bolTagFound
Dim strCount, strDeTag, strExt, strFile, strContent, strRoot, strTag, strText, strTitle, strTitleL
Dim reqImage, reqJavaS, reqLength, reqNumber, reqZip
strFile = ".asp .htm .html .js .txt .css"
strRoot = "/"
strText = Request("SearchText")
strTag = Chr(37) & Chr(62)
bolFileFound = False
bolTagFound = False
If Request("Case") = "on" Then bolCase = 0 Else bolCase = 1
If Request("iImage") = "on" Then reqImage = "If Request("iZips") = "on" Then reqZips = ".zip" Else reqImage = ""
If Request("iJavaS") = "on" Then reqJavaS = "JavaScript" Else reqImage = ""
If Request("rResults") = "10" Then reqNumber = 10
If Request("rResults") = "25" Then reqNumber = 25
If Request("rResults") = "50" Then reqNumber = 50
reqLength = Request("rLength")
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(Server.MapPath(strRoot))
schSubFol(objFolder)
Sub schSubFol(objFolder)
For Each objFile in objFolder.Files
If strCount + 1 > reqNumber or strText = "" Then Exit Sub
If Response.IsClientConnected Then
Set objTextStream = objFSO.OpenTextFile(objFile.Path,fsoForReading)
strContent = objTextStream.ReadAll
If InStr(1, strContent, strTag, bolCase) Then
Else
If Mid(objFile.Name, Len(objFile.Name) - 1, 1) = "." Then strExt = Mid(objFile.Name, Len(objFile.Name) - 1, 2)
If Mid(objFile.Name, Len(objFile.Name) - 2, 1) = "." Then strExt = Mid(objFile.Name, Len(objFile.Name) - 2, 3)
If Mid(objFile.Name, Len(objFile.Name) - 3, 1) = "." Then strExt = Mid(objFile.Name, Len(objFile.Name) - 3, 4)
If Mid(objFile.Name, Len(objFile.Name) - 4, 1) = "." Then strExt = Mid(objFile.Name, Len(objFile.Name) - 4, 5)
If InStr(1, strContent, strText, bolCase) And _
InStr(1, strContent, reqImage, 1) And _
InStr(1, strContent, reqZips, 1) And _
InStr(1, strContent, reqJavaS, 1) And _
Instr(1, strFile, strExt, 1) Then
If InStr(1, strContent, "", 1) Then strTitle = Mid(strContent, InStr(1, strContent, "", 1) + 7, InStr(1, strContent, "", 1)) Else strTitle = "未命名"
strCount = strCount + 1
Response.Write "- "& strCount &" - " & strTitle & "
- "
strTitleL = InStr(1, strContent, "
", 1) - InStr(1, strContent, "", 1) + 7
strDeTag = ""
bolTagFound = False
Do While InStr(strContent, "<")
bolTagFound = True
strDeTag = strDeTag & " " & Left(strContent, InStr(strContent, "<") - 1)
strContent = MID(strContent, InStr(strContent, ">") + 1)
Loop
strDeTag = strDeTag & strContent
If Not bolTagFound Then strDeTag = strContent
If reqLength = "0" Then Response.Write objFile.Path & "
" Else Response.Write Mid(strDeTag, strTitleL, reqLength) & "...
URL: " & objFile.Path & " - 上次修改时间: " & objFile.DateLastModified & " - " & FormatNumber(objFile.Size / 1024) & "Kbytes
"
查看所有2条评论>>