进我的外包
外包服务商
发布项目
寻找项目
欢迎
游客
,
注册
|
登录
|
会员
|
界面
|
简洁版本
|
在线
|
帮助
外包网论坛(威客,威客网,悬赏任务)
外包网论坛(威客,威客网,悬赏任务)
[娱乐][技术][帮助][管理]
=*=外包/威客技术学院=*=
用asp编写类似搜索引擎功能的代码
如何成为一名群主?
本主题被查看44次, 共1个帖子, 1页, 当前为第
1
页 选择页数: 1 跳转到第
页
上一主题
下一主题
标题: 用asp编写类似搜索引擎功能的代码
event
版主
UID: 16051
来自:
精华:
0
积分: 6673
帖子: 6669
注册: 2008-6-10 11:56:00
状态:
离线
包子皮: 4.00
包子馅: 1670.50 元
发短消息
用户资料
树型
回复
引用
只看楼主
2008-11-21 17:32
用asp编写类似搜索引擎功能的代码
我的身份:公司
认证信息:
未实名认证
基本诚信:
0
项目诚信:
0
经验积分:
26
我的服务范围:
尚未填写
首先建一个access 数据库,库中有一个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>
#1
大
中
小
本主题被查看44次, 共1个帖子, 1页, 当前为第
1
页 选择页数: 1 跳转到第
页
论坛跳转...
=*=外包中心;互动中心:打造诚信,高效的交易交流论坛=*=
『 综合信息集散地 』 凝聚智慧,创造财富!
外包任务信息发布大厅(会员查看)
[项目大厅]直接发包项目讨论版
[项目大厅]竞标发包项目讨论版(外包网中介30%保证金到位)
[项目大厅]悬赏发包项目讨论版(外包网中介100%保证金到位)
结束未选中标投票
中标公告
支付公告
商机交流专栏
资源免费分享区
[精品网站源码]下载区
精品网站/设计鉴赏
【营销工具】下载区
[娱乐][技术][帮助][管理]
=*=休闲娱乐=*=『 随便灌水区 』
=*=外包/威客技术学院=*=
外包网论坛管理中心
外包网日常事务
外包网最新公告
建议与投诉
外包网诚信安全档案区
论坛回收站
=*=帮助中心=*=
你问我答
用户注册/实名认证
用户资料/密码修改/评论/收藏
推荐用户赚取佣金
发布竞标/悬赏任务攻略
承接参加任务宝典
举报/投诉
外包网用户使用条款及规则
论坛使用帮助
自由发包常见问题
悬赏任务常见问题
竞标项目常见
现在的时间是 2009-01-09 14:11:31
版权所有
外包网
Powered by
Discuz!NT
1.0.2656 Copyright © 2001-2009
Comsenz Inc
.
Processed in 0.096 seconds
切换界面...
Default
NewSkin