談?dòng)胊sp編寫(xiě)類(lèi)似搜索引擎功能的代碼_ASP教程
教程Tag:暫無(wú)Tag,歡迎添加,賺取U幣!
推薦:FileSystemObject 示例代碼在本節(jié)描述的示例代碼,提供真實(shí)的例子來(lái)示范在 FileSystemObject 對(duì)象模式中可用的許多功能。該代碼顯示了如何一起使用對(duì)象模式的所有功能,以及如何在您自己的代碼中有效地使用這些功能
首先建一個(gè)access 數(shù)據(jù)庫(kù),庫(kù)中有一個(gè)URLINDEX表,其中URL和Keywords字段分別添加了索引,如下:
| 以下為引用的內(nèi)容: URL 文本 (索引:有(無(wú)重復(fù))) Title 文本 Description 文本 Summary 文本 Keywords 文本(索引:有(無(wú)重復(fù))) |
程序文件doquery.asp,代碼:
| 以下為引用的內(nèi)容: <HTML><HEAD><TITLE>簡(jiǎn)單搜索引擎</TITLE></HEAD> <BODY BGCOLOR=#ffffff MARGINWIDTH="0" MARGINHEIGHT="0" LEFTMARGIN=0 TOPMARGIN=0> <FORM METHOD="post" ACTION="doquery.asp?act=search"> Query: <INPUT TYPE="Text" NAME="QueryString"><BR> <INPUT TYPE="Submit" VALUE="Submit"> </FORM> </CENTER> <% dim act act=request("act") if(act="search") then QueryString = Request.form( "QueryString" ) QueryWords = Split( QueryString ) strIndent = " " ’ 如果搜索為空則返回 If QueryString = "" Then Response.Redirect( "default.asp" ) End If Session.timeout = 2 If IsObject(Session("sitesearch_conn")) Then Set conn = Session("sitesearch_conn") Else Set conn = Server.CreateObject("ADODB.Connection") conn.open "driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath("database/SiteSearch.mdb"),"","" Set Session("sitesearch_conn") = conn End If ’ 查詢(xún)語(yǔ)句 sql = "SELECT * FROM [URLIndex] WHERE" ’搜索Description字段 sql = sql & " ( [Description] LIKE ’%" & QueryWords( 0 ) & "%’" ’ First For i = LBound( QueryWords ) 1 to UBound( QueryWords ) If QueryWords( i ) <> "" and UCase( QueryWords(i) ) <> "OR" and UCase( QueryWords(i) ) <> "AND" Then If uCase( QueryWords( i-1 ) ) = "OR" Then sql = sql & " OR [Description] LIKE ’%" & QueryWords( i ) & "%’" Else sql = sql & " AND [Description] LIKE ’%" & QueryWords( i ) & "%’" End If End If Next ’ 搜索Keywords字段 sql = sql & " ) OR ( [Keywords] LIKE ’%" & QueryWords( 0 ) & "%’" For i = LBound( QueryWords ) 1 to UBound( QueryWords ) If QueryWords( i ) <> "" and UCase( QueryWords(i) ) <> "OR" and UCase( QueryWords(i) ) <> "AND" Then If uCase( QueryWords( i-1 ) ) = "OR" Then sql = sql & " OR [Keywords] LIKE ’%" & QueryWords( i ) & "%’" Else sql = sql & " AND [Keywords] LIKE ’%" & QueryWords( i ) & "%’" End If End If Next ’ 搜索Title字段 sql = sql & " ) OR ( [Title] LIKE ’%" & QueryWords( 0 ) & "%’" For i = LBound( QueryWords ) 1 to UBound( QueryWords ) If QueryWords( i ) <> "" and UCase( QueryWords(i) ) <> "OR" and UCase( QueryWords(i) ) <> "AND" Then If uCase( QueryWords( i-1 ) ) = "OR" Then sql = sql & " OR [Title] LIKE ’%" & QueryWords( i ) & "%’" Else sql = sql & " AND [Title] LIKE ’%" & QueryWords( i ) & "%’" End If End If Next ’ 搜索Summary字段 sql = sql & " ) OR ( [Summary] LIKE ’%" & QueryWords( 0 ) & "%’" For i = LBound( QueryWords ) 1 to UBound( QueryWords ) If QueryWords( i ) <> "" and UCase( QueryWords(i) ) <> "OR" and UCase( QueryWords(i) ) <> "AND" Then If uCase( QueryWords( i-1 ) ) = "OR" Then sql = sql & " OR [Summary] LIKE ’%" & QueryWords( i ) & "%’" Else sql = sql & " AND [Summary] LIKE ’%" & QueryWords( i ) & "%’" End If End If Next sql = sql & " )" ’ Set rs = Server.CreateObject("ADODB.Recordset") rs.Open sql, conn, 3, 3 Response.Write "<BR><B> 你搜索的是: </B> " & QueryString Response.Write "<BR><B> 搜索的關(guān)鍵字: </B> " For i = LBound( QueryWords ) to UBound( QueryWords ) Response.Write "<BR>" & strIndent & i & ": " & QueryWords( i ) Next ’ Print the SQL String Response.Write "<BR><B> sql 語(yǔ)句 : </B> " & sql ’ Print the Results Response.Write "<BR><B> 結(jié)果 : </B> <UL>" On Error Resume Next rs.MoveFirst Do While Not rs.eof Response.Write "<BR>" & "<A HREF=’OpenPage.asp?IndexURL=" & rs.Fields("URL").Value & "’>" & rs.Fields("Title") & "</A> - " Response.Write rs.Fields("Description") & "<BR>" Response.Write " <FONT SIZE=2>URL: " & rs.Fields("URL") & "</FONT>" Response.Write "<HR SIZE=1 WIDTH=200 ALIGN=LEFT>" rs.MoveNext Loop Response.Write "</UL>" end if %> </BODY> </HTML> |
分享:如何制作登陸驗(yàn)證頁(yè)面用戶(hù)登錄驗(yàn)證腳本,Chkpwd.asp 以下為引用的內(nèi)容: % '=======用戶(hù)登錄驗(yàn)證腳本======= '如果尚未定義Passed對(duì)象,則將其定義為false,表示沒(méi)有
相關(guān)ASP教程:
- asp FSO 讀寫(xiě)文件本文件實(shí)現(xiàn)代碼
- asp中isNull、isEmpty和空字符串的區(qū)別
- asp獲取用戶(hù)真實(shí)IP地址的方法
- asp連接sqlserver數(shù)據(jù)庫(kù)實(shí)現(xiàn)代碼
- asp中正則表達(dá)式過(guò)濾html代碼函數(shù)
- asp中g(shù)et post提交表單區(qū)別
- 網(wǎng)頁(yè)模板:ASP內(nèi)建對(duì)象Request
- xmlhttp的open方法使用詳解
- ASP的常用的自定義函數(shù)大全
- asp中用for循環(huán)的一個(gè)小技巧
- eWebEditor v3.8 列目錄
- ASP無(wú)組件分頁(yè)實(shí)現(xiàn)思路及代碼
- 相關(guān)鏈接:
- 教程說(shuō)明:
ASP教程-談?dòng)胊sp編寫(xiě)類(lèi)似搜索引擎功能的代碼
。