欢迎光临
我们一直在努力

asp简单的搜索引擎代码-ASP教程,ASP应用

建站超值云服务器,限时71元/月

 

作者:淘特网

出处:http://www.tot.name

注:转载请注明出处

下面是库中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   = “&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;”
 
  如果搜索为空则返回
 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> 结果&nbsp;&nbsp;&nbsp;&nbsp;: </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 “&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<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>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » asp简单的搜索引擎代码-ASP教程,ASP应用
分享到: 更多 (0)

相关推荐

  • 暂无文章