加入收藏
联系我们
关于我们
 您现在的位置: 亿聪 >> 网络学院 >> 网络编程 >> ASP >> 正文  
  使用FSO进行全文检索         
使用FSO进行全文检索
[ 作者:JARON    转贴自:JARON    点击数:3144    更新时间:2004/12/15    文章录入:亿聪 ]
<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
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
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
RealPath=Server.MapPath(strRoot)
VirtualPath="http://" & Request.ServerVariables("SERVER_NAME")
Set objFolder = objFSO.GetFolder(RealPath)
schSubFol(objFolder)
Sub schSubFol(objFolder)
on error resume next
For Each objFile in objFolder.Files
  If 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, 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 = "未命名"
        end if
        myFile=objFile.Path
        myFile=replace(myfile,RealPath,VirtualPath,1,-1,1)
        myFile=replace(myfile,"\","/")
        strCount = strCount + 1
        Response.Write "<DL><DT><B><I>"& strCount  &"</I></B> - <A HREF=" & myFile & ">" & 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
        Response.Write replace(Mid(strDeTag, strTitleL, 200),strText,"<font color=red>" & strText & "</font>",1,-1,bolcase)
        Response.Write "...<BR><b><FONT SIZE='2'>URL: " & myFile
        Response.Write " - 上次修改时间: " & objFile.DateLastModified
        Response.Write " - " & FormatNumber(objFile.Size / 1024)
        Response.Write "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>
  • 上一篇文章: 避免ASP的SQL的执行效率低

  • 下一篇文章: 数字金额转换汉字金额
  • 发表评论】【告诉好友】【打印此文】【关闭窗口
     最新5篇热点文章
  • Knoppix 4.0.2 免硬盘免安…[15797]

  • 通过ASP记录进行分页[20012]

  • ASP开发准则[11932]

  • ASP组件指南[11943]

  • ASP指南[11967]

  •  
     最新5篇推荐文章
  • Knoppix 4.0.2 免硬盘免安…[15797]

  • 如何让Win 2003系统更加安…[13301]

  • Nero超刻简明教程[34139]

  • PS商业实战-来杯茶,行吗?…[7255]

  • ASP深度揭密(下)[12554]

  •  
     相 关 文 章
    没有相关文章

      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
        没有任何评论
    设为首页 | 加入收藏 | 关于我们 | 联系我们 | 友情链接 | 版权声明 | 管理登录
    Copyright © 2000-2022 Yicong.com.All Rights Reserved.
    亿聪 版权所有 E-mail: