asp编写类似搜索引擎功能的代码分享
发布时间:2023-12-23 12:55:56 所属栏目:Asp教程 来源:DaWei
导读: 首先建一个access 数据库,库中有一个URLINDEX表,其中URL和Keywords字段分别添加了索引,如下:
URL 文本 (索引:有(无重复))
Title 文本
Description 文本
Sum
URL 文本 (索引:有(无重复))
Title 文本
Description 文本
Sum
首先建一个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 (编辑:吕梁站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐