First build an Access database. There is a URLINDEX table in the library. Among them, the URL and Keywords fields are added with indexes, as follows:
| The following is the reference content: URL text (index: there (no duplication)) Title text Descripting text Summary text Keywords text (index: there (no duplication)) |
Program file doquery.asp, code:
| The following is the reference content: <HTML> <Head> <Title> Simple Search Engine </Title> </Head> <Bodybgcolor =#FFFFFFFFMARGINWIDTH = 0MARGINHEIGHT = 0 LeftMargin = 0topMargin = 0> <FORMMETHOD = PostAction = Doquery.asp? Act = Search> Query: <inputtype = TextName = queryString> <br> <Inputtype = submitvalue = submit> </Form> </Center> <% dimact ACT = Request (ACT) if (act = search) then QueryString = request.form (querystring) Querywords = split (queryString) Strindent = 'If search is empty, return Ifquerystring = then Response.redirect (default.asp) Endif Session.timeout = 2 IfisObject (Session (Sitesearch_conn) then) then Setconn = session (sitesearch_conn) Else Setconn = Server.CreateObject (Adodb.Connection) conn.Opendriver = {microsoftaccessDriver (*. MDB)}; dbq = & server.mappath (database/sizearch.mdb) ,,, Setsession (sitesearch_conn) = conn Endif 'Query statement sql = select*from [urlindex] where 'Search the description field sql = sql & ([description] like '%& querywords (0) &%' first Fori = lbound (querywords)+1Toubound (querywords) Ifquerywords (i) <> Anducase (querywords (i)) <> orangewords (i)) IfUcase (querywords (i-1)) = ORTHEN sql = sql & or [description] like '%& querywords (i) &%' Else SQL = SQL & And [Description] LIKE '%& Querywords (i) &%' Endif Endif Next 'Search Keywords field sql = sql &) or ([Keywords] like '%& querywords (0) &%' Fori = lbound (querywords)+1Toubound (querywords) Ifquerywords (i) <> Anducase (querywords (i)) <> orangewords (i)) IfUcase (querywords (i-1)) = ORTHEN SQL = SQL & OR [Keywords] like '%& querywords (i) &%' Else SQL = SQL & And [Keywords] like '%& querywords (i) &%' Endif Endif Next 'Search Title field sql = sql &) or ([title] like '%& querywords (0) &%' Fori = lbound (querywords)+1Toubound (querywords) Ifquerywords (i) <> Anducase (querywords (i)) <> orangewords (i)) IfUcase (querywords (i-1)) = ORTHEN SQL = SQL & OR [Title] like '%& querywords (i) &%' Else SQL = SQL & And [Title] like '%& querywords (i) &%' Endif Endif Next 'Search Summary field sql = sql &) or ([Summary] like '%& querywords (0) &%' Fori = lbound (querywords)+1Toubound (querywords) Ifquerywords (i) <> Anducase (querywords (i)) <> orangewords (i)) IfUcase (querywords (i-1)) = ORTHEN sql = SQL & OR [Summary] like '%& querywords (i) &%' Else sql = SQL & And [Summary] like '%& querywords (i) &%' Endif Endif Next SQL = SQL &) ' Setrs = server.createObject (Adodb.oldSet) RS.OPENSQL, CONN, 3,3 Response.write <br> <b> What you searched is: </b> & querystring Response.write <br> <b> Search keywords: </b> Fori = lbound (querywords) Toubnsnd (querywords) Response.write <br> & Strindent & I &: & Querywords (i) Next 'Printthesqlstring Response.write <br> <b> SQL statement: </b> & sql 'Printtheresults Response.write <br> <b> Result: </b> <ul> OnerRerSumenext rs.movefired Dowhilenotrs.eof Response.write <br> & <ahref = 'OpenPage.asp? Indexurl = & rs.fields (url). Value &'> & rs.fields (title) & </a>- Response.writers.fields (description) & <br> Response.write <fontsize = 2> url: & rs.fields (url) & </font> Response.write <hrsize = 1width = 200ALIGN = left> rs.movenext Loop Response.write </ul> endif %> </Body> </Html> |