Below is the urlindex table in the Library: the URL and keywords fields are indexed respectively.
URL text (Index: Yes (no duplicates ))
Title text
Description text
Summary text
Keywords text (Index: Yes (no duplicates ))
Doquery. asp
<HTML> <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 the search is empty, return
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
'Query statement
SQL = "select * from [urlindex] Where"
'Search the description field.
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
'Search for the keywords Field
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
'Search for the title Field
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
'Search for the 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> you searched for: </B>" & querystring
Response. Write "<br> <B> Keyword: </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 statement: </B>" & SQL
'Print the results
Response. Write "<br> <B> result: </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>