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

作者:网络 来源:佚名 更新时间:2008-11-23 17:18:57 点击:
<%
response.buffer=true

'
' onefile search engine (ofsearch v1.0)
' copyright ?000 sixto luis santos <[email protected]>
' 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 = "&nbsp;&nbsp;<b>" & docmatchcount & ".</b>&nbsp;"
' 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>&nbsp;&nbsp;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(