您的位置:首页网页设计ASP实例 → asp简单的搜索引擎代码

asp简单的搜索引擎代码

时间:2009/12/15 11:34:00来源:本站整理作者:我要评论(0)

本篇告诉你asp简单的搜索引擎代码:

下面是库中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


 ' 搜索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>


 

相关视频

    没有数据

相关阅读 几个常用搜索引擎代码全境封锁2easy anti cheat错误解决方法dnfSPTP改版内容介绍2019 dnfSPTP技能改版详情Astral Chain发售日期一览 Astral Chain什么时候出阴阳师SP御馔津正式曝光 阴阳师SP稻荷神御馔津降临平安京阴阳师SP御馔津带什么御魂 阴阳师SP御馔津御魂搭配推荐阴阳师SP御馔津技能是什么 阴阳师SP御馔津技能一览阴阳师SP御馔津曝光 春节双SP降临平安京

文章评论
发表评论

热门文章 没有查询到任何记录。

最新文章 迅雷新手完全入门手册 asp下面javascript上传图片限制格式大小方法告诉大家网页弹出窗口应用总结ASP常见错误类型大全asp常见错误分析和解决办法

人气排行 总是弹出visual studio 实时调试器 三种解决SQLSERVER存储过程及调用详解Asp获取真实IP地址ASP中连接Mssql的几种方法一个简单好用的UBB编辑器(含代码)如何用Split将字符串转换为数组并获取数组下ASP防止表单重复提交的办法告诉你免费的简单聊天室源代码