Search engine
The following is the Urlindex table in the library: the URL and keywords fields are indexed separately.
URL Text (index: There is (No duplicates))
Title text
Description text
Summary text
Keywords Text (index: There is (No duplicates))
Doquery.asp
<HTML><HEAD><TITLE> Simple search Engine </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 = ""
' Returns if the search is empty
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)};d bq=" & Server.MapPath ("Database/sitesearch.mdb"), "", ""
Set session ("sitesearch_conn") = conn
End If
' Query statement
sql = "SELECT * from [Urlindex] WHERE"
' Search Description field
sql = SQL & ' ([Description] like '% ' & QueryWords (0) & "% '" &n bsp; ' a
for i = LBound (querywords) + 1 to UBound (querywords)
if querywords (i) < > "" and UCase (QueryWords (i)) <> "OR" and UCase (QueryWords (i)) <> "and" Then
if UC ASE (QueryWords (i-1)) = "OR" Then
sql = sql & "OR [Description] like '%" & Querywor DS (i) & "% '"
else
sql = SQL & "And [Description] like '%" & QueryWords (i) & "% '"
end if
end if
next
' Search Keywords field
sql = SQL & ') OR ([Keywords] like '% ' & QueryWords (0) & "%"
f or i = LBound (querywords) + 1 to UBound (querywords)
if querywords (i) <> "" and UCase (Queryword S (i) <> "OR" and UCase (QueryWords (i)) <> "and" Then
if UCase (querywords) = " or "Then
sql = sql &" OR [Keywords] like '% "& QueryWords (i) &"% "
&nb Sp; else
sql = SQL & "And [Keywords] like '%" & QueryWords (i) & "%"
&nb Sp; end if
end if
next
' Search Title field
sql = sql & ') OR ([Title] like '% ' & QueryWords (0) & "%" Br> for i = LBound (querywords) + 1 to UBound (querywords)
if querywords (i) <> "" "and UCase ( QueryWords (i) <> "OR" and UCase (QueryWords (i)) <> "and" Then
if UCase (i -1) = "or" Then
sql = sql & OR [Title] like '% ' & QueryWords (i) & "%"
&N Bsp; else
sql = SQL & "And [Title] like '%" & QueryWords (i) & "%"
end if
end if
next
' Search Summary field
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> your search is: </B> "& querystring
Response.Write "<BR><B> Search Keywords: </B>"
for i = LBound (querywords) to UBound (querywords)
response.write "<BR>" & Strindent & I & ":" & QueryWords (i)
next
' Print ' SQL String
Response.Write "<BR><B> SQL statements: </B>" & SQL
' Print the Results
Response.Write "<BR><B> results: </B> <UL>"
On Error Resume Next
Rs. MoveFirst
Do as 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 "Rs. MoveNext
Loop
Response.Write "</UL>"
End If
%>
</BODY>
</HTML>