如何實(shí)現(xiàn)全文檢索?
<%@ LANGUAGE="VBscript" %>
<html>
<head>
<meta NAME="GENERATOR" Content="Microsoft FrontPage 3.0">
<meta HTTP-EQUIV="Content-Type" content="text/html; charset=gb_2312-80">
<title>星河影動(dòng)之全文檢索</title>
<meta name="Microsoft Border" content="tl, default">
</head>
<body BGPROPERTIES="FIXED" BGCOLOR="#00FFFF">
<%
mousepointer=13
Set Conn1 = Server.CreateObject("ADODB.Connection")
conn1.open "DSN=intels"
Set rcst1 = conn1.execute("select * from pages_catalogue")
sch_str=request.form("text1")
doubbytes=len(sch_str)\2
sch_str=left(sch_str,doubbytes)
' 匹配字串的長(zhǎng)度.預(yù)處理Request取得的數(shù)據(jù)(用戶輸入的有用信息), 通過(guò)計(jì)算有效信息長(zhǎng)度來(lái)截取所需的字串.我們也可以在輸入字串后附加一標(biāo)志字符(如#或chr(7))來(lái)處理.
Response.Write "<CENTER>檢索結(jié)果<HR><Br>"
Dim result
result =false
Response.Write "<UL>"
do while not rcst1.eof
tit=rcst1.fields("file_title")
fn=rcst1.fields("file_name")
file_name= Server.MapPath ("/") & "\song\chunfeng\" & fn
to_find=text_match(file_name,sch_str)
' 逐個(gè)打開(kāi)記錄集中當(dāng)前記錄所指向的文件。用查找的字串對(duì)文件的全文本進(jìn)行匹配比較.
if to_find then
url="chunfeng/" & fn
Response.Write "<A HREF=" & url & ">
" & tit
end if
rcst1.movenext
result=result or to_find
loop
Response.Write "</UL>"
' 把符合條件的文件標(biāo)題以超級(jí)鏈接形式輸出到客戶端.
if not result then
Response.Write "對(duì)不起,沒(méi)有找到!"
end if
mousepointer=0
%>
<script RUNAT="Server" LANGUAGE="VBScript">
function text_match(filename,search_string)
dim retstring
dim find_pos
Dim fso, a
dim done
text_match=false
Set fso = Server .CreateObject("Scripting.FileSystemObject
")
' 創(chuàng)建腳本的文件系統(tǒng),打開(kāi)文本流以讀入.
Set a = fso.OpenTextFile(filename, 1, FALSE)
done=a.AtEndOfStream or text_match
Do While not done
retstring = a.ReadLine
find_pos=instr(retstring,search_string)
if find_pos>0 then text_match=true
done=a.AtEndOfStream or text_match
Loop
a.Close
end function
</script>
</body></html>
[1]
相關(guān)文章
如何實(shí)現(xiàn)文件上傳并自動(dòng)歸類功能?
如何實(shí)現(xiàn)文件上傳并自動(dòng)歸類功能?...2006-11-11如何最準(zhǔn)確地統(tǒng)計(jì)在線用戶數(shù)?
如何最準(zhǔn)確地統(tǒng)計(jì)在線用戶數(shù)?...2006-11-11如何讓用戶再次訪問(wèn)我的網(wǎng)站時(shí)不需再提交相關(guān)信息?
如何讓用戶再次訪問(wèn)我的網(wǎng)站時(shí)不需再提交相關(guān)信息?...2006-11-11