当前位置: 代码网 > it编程>编程语言>其他编程 > 如何用FileSystemObject组件来做一个站内搜索?

如何用FileSystemObject组件来做一个站内搜索?

2024年05月18日 其他编程 我要评论
searchpage.htm' 搜索页面.<html><head> <title>千花飞舞之站内搜索引擎</title> </head&g

searchpage.htm
' 搜索页面.

<html>

<head>
        <title>
千花飞舞之站内搜索引擎</title>
    </head>
    <body>
        <center>
            <form method=post action="searchresult.asp">

    <table bgcolor="#blue" border="0">
      <tr>                       
        <td rowspan="3" bgcolor="#blue" width="21" nowrap></td>
        <td width="363" nowrap> <font color="#ffffff">
          <input type="text" name="searchtext" size="22">
           <input type="checkbox" name="case">
         
高度敏感</font> </td>
        <td rowspan="3" width="10">
          <input type="submit" value="
搜索">
                                <p>
          <input type="reset" value="
重写">
                        </td>
        <td rowspan="3" bgcolor="#blue" width="28"></td>
                    </tr>
                    <tr>

        <td width="363" nowrap> <font color="#ffffff">
搜索返回结果
          <select name="rlength" >
            <option value="200" selected>
详细信息</option>
            <option value="100">
简短信息</option>
            <option value="0">
只返回连接</option>
          </select>
                                <select name="rresults">
                                    <option value="10" selected>10
                                    <option value="25">25
                                    <option value="50">50
                                </select>
                            </font>
                        </td>
                    </tr>
                    <tr>

        <td width="363" nowrap> <font color="#ffffff">
必须包含:
        <input type="checkbox" name="iimage">
图片
        <input type="checkbox" name="izips">zip
格式
        <input type="checkbox" name="ijavas"> javascript
                            </font>
                        </td>
                    </tr>
                </table>
            </form>
            </center>
<dl>
</dl>
</body></html>

searchresult.asp
' 搜索结果.
<html>
<head>
<title>
千花飞舞站内'<%=request("searchtext")%>'之搜索结果</title>
</head>
<body>
<b>'<%=request("searchtext")%>'
的搜索结果</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" else 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, "<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></a></dt><br><dd>"
                    strtitlel = instr(1, strcontent, "</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 & "</dd></dl>" else response.write
mid(strdetag, strtitlel, reqlength) & "...<br><b><font size='2'>url: " & objfile.path & " -
上次修改时
: " & objfile.datelastmodified & " - " & formatnumber(objfile.size / 1024)
& "kbytes</font></b></dd></dl>"
                    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
%>
</body></html>

 

 

[1]

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com