|
<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
搜索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> 搜索的关键字: </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 语句 : </b> ” & sql print the results response.write “<br><b> 结果 : </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>
|