7/26/00
 Quick Links :
home| forum | whats new | advertise | contact us




Overview
Access Database
Indexing using HTTP protocol
Indexing using FilySystemObject
Deleting URLs from Database
HTML Search Engine Form
Searching Records in the Database
Include File
Conclusion

WantJava.com


Please support our sponsors

Creating 'search.asp' page :

Create a new ASP page and name it 'search.asp'. Copy paste the following code into it :

   <!--#include file="editme.asp"-->
   <!--#include file="adovbs.inc"-->
   <html>
   <head>
      <style>
         body { font-family : Verdana; font-size : 8pt; }
      </style>
   </head>
   <body>

 <%
   'On Error Resume Next
   Dim geturl, title, description, keywords, strURL, strDB, rs, strKeyword
   Dim urlshown, records, recordsToShow, n, con, currentPage, show

      If Len(Request.QueryString("currentPage")) = 0 Then
            currentPage = 1
      Else
            currentPage = Request.QueryString("currentPage")
      End If

      records = ""
      recordsToShow = 10
      n = 0

      ' Keyword to search
      strKeyword = split(Trim(Request.QueryString("look_for")), " ")

      ' Our Connection Object
      Set con = CreateObject("ADODB.Connection")
      con.Open strDB

      ' Our Recordset Object
      Set rs = CreateObject("ADODB.Recordset")
      rs.CursorLocation = adUseClient
      rs.CacheSize = recordsToShow
      show = True

      ' Searching the records for the keywords entered
      Select Case UBound(strKeyword)
            Case 0 rs.Open "select * from all_pages where keywords like '%" _
                  & strKeyword(0) & "%' order by mydate desc", con
            Case 1 rs.Open "select * from all_pages where keywords like '%" _
                  & strKeyword(0) & "%' and keywords like '%" & strKeyword(1) & _
                  "%' order by mydate desc", con
            Case 2 rs.Open "select * from all_pages where keywords like '%" _
                  & strKeyword(0) & "%' and keywords like '%" & strKeyword(1) & _
                  "%' and keywords like '%" & strKeyword(2) & "%' order by _
                  mydate desc", con
            Case Else rs.Open "select * from all_pages where keywords like '%" _
                  & strKeyword(0) & "%' and keywords like '%" & strKeyword(1) & _
                  "%' and keywords like '%" & strKeyword(2) & "%' order by _
                  mydate desc", con
            End Select

      ' If the returning recordset is not empty
      If Not rs.EOF Then

      records = records & "found"
      rs.PageSize = recordsToShow
      totalpages = rs.PageCount
      rs.AbsolutePage = currentPage

      ' Showing total number of pages found and the current page number
      Response.Write "Displaying Page " & currentPage & " of " & totalPages & "<br>"
      Response.Write "Total Records Found : " & rs.RecordCount
      Response.Write "<br><br>"

      ' Showing relevant records
      Do Until rs.EOF
      ' Showing only 10 records at a time
      If n = recordsToShow Then
      Exit Do
      End If

            If InStr(1, urlshown, rs("url"), 1) = 0 Then

            Response.Write "<b><a href=""" & rs("url") & """>" & rs("title") & _
                  "</a></b><br>" & vbcrlf
            Response.Write "" & rs("description") & "<br>" & vbcrlf
            Response.Write "URL : " & rs("url") & "</b><br>" & vbcrlf
            Response.Write "Last indexed on : " & rs("mydate") & "<br><br>" & vbcrlf

            n = n + 1
            End If

            urlshown = urlshown & " " & rs("url") & " "
            rs.MoveNext
      Loop

      For i = 0 To UBound(strKeyword)
            strKeyword2 = strKeyword(i)
      Next
      look_for = strKeyword2

      ' Links to move through the records
      If currentPage > 1 Then
            Response.Write "<a href=""" & Request.ServerVariables("SCRIPT_NAME") & _
                  "?currentPage=" & currentPage - 1 & "&look_for=" & look_for & _
                  """>Back</a>"
            Else
            Response.Write "<u style=""color : silver;"">Back</u>"
      End If

      Response.Write "          "

      If CInt(currentPage) <> CInt(totalPages) Then
            Response.Write "<a href=""" & Request.ServerVariables("SCRIPT_NAME") & _
                  "?currentPage=" & currentPage + 1 & "&look_for=" & look_for & _
                  """>Next</a>"
            Else
            Response.Write "<u style=""color : silver;"">Next</u>"
      End If

      End If

      ' Done. Now release Objects
      con.Close
      Set con = Nothing
      Set rs = Nothing

   If InStr(1, records, "found", 1) = 0 Then
   Response.Write "<b>Sorry, no matching record was found.</b>" & vbcrlf
   End If
 %>
   </body></html>

On the next page we will review the above code.



Next -> 




© 1999-2000 Faisal Khan, All rights reserved