该搜索引擎由一个HTM文件一个ASP文件组成,主要是运用FILESYSTEMOBJECT组件来达到目的,功能强大,修改界面以后可以直接拿来使用,当然加上一点自己的东西就更加好了。
searchpage.htm
该HTM文件用来传入条件
1<html>
2<head>
3<title>ASP搜索引擎范例</title>
4</head>
5<body>
6<center>
7<form action="search.asp" method="POST">
8<table bgcolor="#CC6633" border="0">
9<tr>
10<td bgcolor="#CC6633" nowrap="" rowspan="3" width="21"> </td>
11<td nowrap="" width="363"> <font color="#FFFFFF">
12<input name="SearchText" size="22" type="text"/>
13<input name="Case" type="checkbox"/>
14高度敏感</font> </td>
15<td rowspan="3" width="10">
16<input type="submit" value="确定"/>
17<p>
18<input type="reset" value="清除"/>
19</p></td>
20<td bgcolor="#CC6633" rowspan="3" width="28"> </td>
21</tr>
22<tr>
23<td nowrap="" width="363"> <font color="#FFFFFF"> 返回结果
24<select name="rLength">
25<option selected="" value="200">长信息 </option>
26<option value="100">短信息</option>
27<option value="0">只返回连接</option>
28</select>
29<select name="rResults">
30<option selected="" value="10">10
31<option value="25">25
32<option value="50">50
33</option></option></option></select>
34</font>
35</td>
36</tr>
37<tr>
38<td nowrap="" width="363"> <font color="#FFFFFF"> 必须包括:
39<input name="iImage" type="checkbox"/>
40图片
41<input name="iZips" type="checkbox"/>
42Zip格式
43<input name="iJavaS" type="checkbox"/> JavaScript
44</font>
45</td>
46</tr>
47</table>
48</form>
49</center>
50<dl>
51<dd> </dd>
52</dl>
53</body>
54</html>
------------------------------------------------------------------------
显示结果的ASP程序
search.asp
1<html>
2<head>
3<title>'```
4=Request("SearchText")
5```'的搜索结果</title>
6</head>
7<body>
8<b>'```
9=Request("SearchText")
10```'的搜索结果</b><br/>
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 = "<img" +="" 1="" each="" else="" for="" if="" in="" objfile="" objfolder="objFSO.GetFolder(Server.MapPath(strRoot))" objfolder.files="" objfso='Server.CreateObject("Scripting.FileSystemObject")' reqimage="" reqjavas="JavaScript" reqlength='Request("rLength")' reqnumber="50" request("ijavas")="on" request("izips")="on" request("rresults")="50" reqzips=".zip" schsubfol(objfolder)="" set="" strcount="" sub="" then=""> 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, "<title>", 1) Then strTitle = Mid(strContent, InStr(1, strContent, "<title>", 1) + 7, InStr(1, strContent, "</title>", 1)) Else strTitle = "未命名"
strCount = strCount + 1
Response.Write "<dl><dt><b><i>"& strCount &"</i></b> - <a href=" & objFile.Path & ">" & strTitle & "</a></dt><br/><dd>"
strTitleL = InStr(1, strContent, "</dd></dl></title>", 1) - InStr(1, strContent, "<title>", 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) & "...<br/><b><font size="2">URL: " & objFile.Path & " - 上次修改时间: " & objFile.DateLastModified & " - " & FormatNumber(objFile.Size / 1024) & "Kbytes</font></b>"
bolFileFound = True
End If
objTextStream.Close
End If
End If
Next
End Sub
For Each objSubFolder in objFolder.SubFolders
schSubFol(objSubFolder)
Next
If Not bolFileFound then Response.Write "没有匹配结果"
If bolFileFound then Response.Write "<b>搜索结束</b>"
Set objTextStream = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
1</title></img"></body></html>