<% 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 '%" & Q