解讀用asp編寫類似搜索引擎功能的代碼_ASP教程

      編輯Tag賺U幣
      教程Tag:暫無Tag,歡迎添加,賺取U幣!

      推薦:揭秘解決殺毒軟件誤刪asp文件的方法
      一些殺毒軟件經(jīng)常會把某些asp文件當成病毒刪除,有時簡直防不勝防,程序莫名其妙的就不能用了,因為少了文件呀~~。這主要是因為,殺毒軟件將某些asp代碼當成木馬關鍵詞,記錄保存著,所以遇到有這個關鍵詞,就會禁止運行或刪除。 解決的方法是將這些關鍵詞給

      首先建一個access 數(shù)據(jù)庫,庫中有一個URLINDEX表,其中URL和Keywords字段分別添加了索引,如下:
      URL             文本 (索引:有(無重復))
      Title            文本
      Description 文本
      Summary    文本
      Keywords   文本(索引:有(無重復))

      程序文件doquery.asp,代碼:
      <HTML><HEAD><TITLE>簡單搜索引擎</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

       ’ 查詢語句
       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
       

      分享:揭秘17個ASP編程基礎典型代碼
      1.ASP取得表格輸入數(shù)據(jù)的方法:GETPOST 一.get:用戶端將數(shù)據(jù)加到URL后,格式為”?字段1=輸入數(shù)據(jù)1字段2=輸入數(shù)據(jù)2...,再將其送到服務器。如:action為www.abc.com,字段Name輸入數(shù)據(jù)為jack,字段age的數(shù)據(jù)為15,則用get方法為http://www.abc.com?Name=jackAge=

      共2頁上一頁12下一頁
      來源:模板無憂//所屬分類:ASP教程/更新時間:2010-02-25
      相關ASP教程