中华网校

系列网站: 中华网校 | www.网校.com | 3D模型 | 中华网校教育

电脑网校 | 业界新闻 | 职业网校 | 网校宝典 | 软件下载 | 网校论坛 | 网校联盟

电脑入门 | 网页设计 | 网络编程 | 图形图象 | 三维空间 | 多媒体 | 程序语言 | 操作系统 | 系统专题 | 办公应用 | 软件宝典 | 硬件天下 | 

 

您的位置:首页 >> 软件宝典 >> 其它软件 >> 新闻正文

制作一个个人搜索引擎(源码)  

作者:_  时间:2004-7-10  来自:中华网校  责任编辑:  阅读次数:

<%
Response.Buffer=True

'
' OneFile Search Engine (ofSearch v1.0)
' Copyright ?000 Sixto Luis Santos <sixtos@prtc.net>
' All Rights Reserved
'
' Note:
' This program is freeware. This program is NOT in the Public Domain.
' You can freely use this program in your own site.
'
' You cannot re-distribute the code, by any means,
' without the express written authorization by the author.
'
' Use this program at your own risk.
'


' Globals --------------------------------------
' ----------------------------------------------

Const ValidFiles = "htmltxt"
Const RootFld = "./"

Dim Matched
Dim Regex
Dim GetTitle
Dim fs
Dim rfLen
dim RootFolder
Dim DocCount
Dim DocMatchCount
Dim MatchedCount

' ----------------------------------------------
' Procedure: SearchFiles()
' ----------------------------------------------
Public Sub SearchFiles(FolderPath)
Dim fsFolder
Dim fsFolder2
Dim fsFile
Dim fsText
Dim FileText
Dim FileTitle
Dim FileTitleMatch
Dim MatchCount
Dim OutputLine

' Get the starting folder
Set fsFolder = fs.GetFolder(FolderPath)
' Iterate thru every file in the folder
For Each fsFile In fsFolder.Files
' Compare the current file extension with the list of valid target files
If InStr(1, ValidFiles, Right(fsFile.Name, 3), vbTextCompare) > 0 Then
DocCount = DocCount + 1
' Open the file to read its content
Set fsText = fsFile.OpenAsTextStream
FileText = fsText.ReadAll
' Apply the regex search and get the count of matches found
MatchCount = Regex.Execute(FileText).Count
MatchedCount = MatchedCount + MatchCount
If MatchCount > 0 Then
DocMatchCount = DocMatchCount + 1
' Apply another regex to get the html document's title
Set FileTitleMatch = GetTitle.Execute(FileText)
If FileTitleMatch.Count > 0 Then
' Strip the title tags
FileTitle = Trim(replace(Mid(FileTitleMatch.Item(0),8),"</title>","",1,1,1))
' In case the title is empty
If FileTitle = "" Then
FileTitle = "No Title (" & fsFile.Name & ")"
End If
Else
' Create an alternate entry name (if no title found)
FileTitle = "No Title (" & fsFile.Name & ")"
End If
' Create the entry line with proper formatting
' Add the entry number
OutputLine = "  <b>" & DocMatchCount & ".</B> "
' Add the document name and link
OutputLine = OutputLine & "<A href=" & chr(34) & RootFld & replace(Mid(fsFile.Path,
rfLen),"\","/") & chr(34) & "><B>"
OutputLine = OutputLine & FileTitle & "</B></a>"
' Add the document information
OutputLine = OutputLine & "<font size=1><br>  Criteria matched " & MatchCount
& " times - Size: "
OutputLine = OutputLine & FormatNumber(fsFile.Size / 1024,2 ,-1,0,-1) & "K bytes"
OutputLine = OutputLine & " - Last Modified: " & formatdatetime
(fsFile.DateLastModified,vbShortDate) & "</Font><br>"
' Display entry
Response.Write OutputLine
Response.Flush
End If
fsText.Close
End If
Next

' Iterate thru each subfolder and recursively call this procedure
For Each fsFolder2 In fsFolder.SubFolders
SearchFiles fsFolder2.Path
Next

Set FileTitleMatch = Nothing
Set fsText = Nothing
Set fsFile = Nothing
Set fsFolder2 = Nothing
Set fsFolder = Nothing
End Sub

' ----------------------------------------------
' Procedure: Search()
' ----------------------------------------------
Sub Search(SearchString)
Dim i
Dim fKeys
Dim fItems

Set fs = CreateObject("Scripting.FileSystemObject")
Set GetTitle = New RegExp
Set Regex = New RegExp

With Regex
.Global = True
.IgnoreCase = True
.Pattern = Trim(SearchString)
End With
With GetTitle
.Global = False
.IgnoreCase = True
.Pattern = "<title>(.|\n)*</title>"
End With

RootFolder = Server.MapPath(RootFld)

If Right(RootFld,1) <> "/" Then
RootFld = RootFld & "/"
End If

If Right(RootFolder, 1) <> "\" Then
RootFolder = RootFolder & "\"
End If
rfLen = Len(RootFolder) + 1

SearchFiles RootFolder

If MatchedCount = 0 Then
Response.Write "  <B>No Matches Found.</b><BR>

   制作一个个人搜索引擎(源码)   共有2页  1  2 页

相关文章 最新文章 推荐文章
Applet的路径配置
从数据表中取出第n条到第m条的记录的方法
制作一个个人搜索引擎(源码)

  中华网校依法保护知识产权,如果我们的文章有涉及或侵犯您的有关权益,请即时与我们 联系, 注明网址及文章,我们会即时处理或删除,感谢您的合作!中华网校email
  中华网校由广州市中六电脑城智锐计算机专业培训学院及中华网校技术中心提供网络支持未经本站许可任何个人网站、书刊报社一律不得私自复制,转载本站内容!

关于中华网校 | 广告服务 | 版权声明 | 投稿指南 | 网站合作 | 友情链接 | 网站地图

 

版权所有 中华网校 & 智锐网校 1999-2004 COPYRIGHT (C) 1999-2004 www.ZhiRui.com ALL RIGHTS RESERVED

 
/**/