asp

位置:IT落伍者 >> asp >> 浏览文章

用asp编写类似搜索引擎功能的代码


发布日期:2022年08月22日
 
用asp编写类似搜索引擎功能的代码

首先建一个access 数据库库中有一个URLINDEX表其中URL和Keywords字段分别添加了索引如下

                        URL 文本(索引:有(无重复))
            Title文本
            Description文本
            Summary文本
            Keywords文本(索引:有(无重复)) 程序文件doqueryasp代码
                                                                        <HTML><HEAD><TITLE>简单搜索引擎</TITLE></HEAD>
                        <BODYBGCOLOR=#ffffffMARGINWIDTH=""MARGINHEIGHT=""
                        LEFTMARGIN=TOPMARGIN=>
                        <FORMMETHOD="post"ACTION="doqueryasp?act=search">
                        Query:<INPUTTYPE="Text"NAME="QueryString"><BR>
                        <INPUTTYPE="Submit"VALUE="Submit">
                        </FORM>
                        </CENTER>
                        
                        
                        <%
                        dimact
                        act=request("act")
                        if(act="search")then
                        QueryString=Requestform("QueryString")
                        QueryWords=Split(QueryString)
                        strIndent=""
                        
                        ’如果搜索为空则返回
                        IfQueryString=""Then
                        ResponseRedirect("defaultasp")
                        EndIf
                        
                        Sessiontimeout=
                        IfIsObject(Session("sitesearch_conn"))Then
                        Setconn=Session("sitesearch_conn")
                        Else
                        Setconn=ServerCreateObject("ADODBConnection")
                        connopen"driver={MicrosoftAccessDriver(*mdb)};dbq="&ServerMapPath("database/SiteSearchmdb")""""
                        SetSession("sitesearch_conn")=conn
                        EndIf
                        
                        ’查询语句
                        sql="SELECT*FROM[URLIndex]WHERE"
                        
                        ’搜索Description字段
                        sql=sql&"([Description]LIKE’%"&QueryWords()&"%’"’First
                        Fori=LBound(QueryWords)+toUBound(QueryWords)
                        IfQueryWords(i)<>""andUCase(QueryWords(i))<>"OR"andUCase(QueryWords(i))<>"AND"Then
                        IfuCase(QueryWords(i))="OR"Then
                        sql=sql&"OR[Description]LIKE’%"&QueryWords(i)&"%’"
                        Else
                        sql=sql&"AND[Description]LIKE’%"&QueryWords(i)&"%’"
                        EndIf
                        EndIf
                        Next
                        
                        ’搜索Keywords字段
                        sql=sql&")OR([Keywords]LIKE’%"&QueryWords()&"%’"
                        Fori=LBound(QueryWords)+toUBound(QueryWords)
                        IfQueryWords(i)<>""andUCase(QueryWords(i))<>"OR"andUCase(QueryWords(i))<>"AND"Then
                        IfuCase(QueryWords(i))="OR"Then
                        sql=sql&"OR[Keywords]LIKE’%"&QueryWords(i)&"%’"
                        Else
                        sql=sql&"AND[Keywords]LIKE’%"&QueryWords(i)&"%’"
                        EndIf
                        EndIf
                        Next
                        
                        ’搜索Title字段
                        sql=sql&")OR([Title]LIKE’%"&QueryWords()&"%’"
                        Fori=LBound(QueryWords)+toUBound(QueryWords)
                        IfQueryWords(i)<>""andUCase(QueryWords(i))<>"OR"andUCase(QueryWords(i))<>"AND"Then
                        IfuCase(QueryWords(i))="OR"Then
                        sql=sql&"OR[Title]LIKE’%"&QueryWords(i)&"%’"
                        Else
                        sql=sql&"AND[Title]LIKE’%"&QueryWords(i)&"%’"
                        EndIf
                        EndIf
                        Next
                                                                                                

                        ’搜索Summary字段
            sql=sql&")OR([Summary]LIKE’%"&QueryWords()&"%’"
            Fori=LBound(QueryWords)+toUBound(QueryWords)
            IfQueryWords(i)<>""andUCase(QueryWords(i))<>"OR"andUCase(QueryWords(i))<>"AND"Then
            IfuCase(QueryWords(i))="OR"Then
            sql=sql&"OR[Summary]LIKE’%"&QueryWords(i)&"%’"
            Else
            sql=sql&"AND[Summary]LIKE’%"&QueryWords(i)&"%’"
            EndIf
            EndIf
            Next
            
            sql=sql&")"
            
            
            ’
            Setrs=ServerCreateObject("ADODBRecordset")
            rsOpensqlconn
            
            ResponseWrite"<BR><B>你搜索的是:</B>"&QueryString
            
            ResponseWrite"<BR><B>搜索的关键字:</B>"
            Fori=LBound(QueryWords)toUBound(QueryWords)
            ResponseWrite"<BR>"&strIndent&i&":"&QueryWords(i)
            Next
            
            ’PrinttheSQLString
            ResponseWrite"<BR><B>sql语句:</B>"&sql
            
            ’PrinttheResults
            ResponseWrite"<BR><B>结果:</B><UL>"
            OnErrorResumeNext
            rsMoveFirst
            DoWhileNotrseof
            ResponseWrite"<BR>"&"<AHREF=’OpenPageasp?IndexURL="&rsFields("URL")Value&"’>"&rsFields("Title")&"</A>"
            ResponseWritersFields("Description")&"<BR>"
            ResponseWrite"<FONTSIZE=>URL:"&rsFields("URL")&"</FONT>"
            ResponseWrite"<HRSIZE=WIDTH=ALIGN=LEFT>"
            rsMoveNext
            Loop
            ResponseWrite"</UL>"
            
            endif
            %>
            
            
            </BODY>
            </HTML>
                        

               

上一篇:asp 非法关键词过滤程序

下一篇:asp生成目录与无限生成多级目录创建