How to use ASP to realize full text search in the Web site?
we can first create a database that contains the file name, file title, and retrieve the file, then use ADO to access it and set up the Recordset object. See below for specific code and description:
<%@ language= "VBSCRIPT"%>
<html>
<head>
<meta name= "generator" content= "Microsoft FrontPage 3.0" >
<meta http-equiv= "Content-type" content= "text/html"; Charset=gb_2312-80 ">
Full-Text Search </title>
of
<title> wonderful spring Breeze
<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)
' matches the length of the string. Preprocessing the data obtained by the request (user input useful information), by calculating the length of effective information to intercept the required string. We can also attach a glyph (such as # or CHR (7)) to the input string after it is processed.
Response.Write "<CENTER> search results <HR><Br>"
Dim Result
result =false
Response.Write "
"
do, 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)
' opens the file that the current record in the recordset points to. Match the Full-text text of a file with a search string to compare
......
Response.Write "<a href=" & URL & ">
"& Tit
End If
Rcst1.movenext
Result=result or To_find
Loop
Response.Write "
"
' Output the eligible file headers to the client in hyperlink form
if not result then
Response.Write "Sorry, not found!"
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
")
' Create script file system, open text stream to read
Set a = fso. OpenTextFile (filename, 1, FALSE)
Done=a.atendofstream or Text_match
do
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>