asp简单的搜索引擎代码
2008-02-23 09:38:56来源:互联网 阅读 ()
下面是库中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>
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash