Signup · Login
Stardeveloper.com  
Home · Articles · Forums · Advertise · Contact
Search this Website
Newsletter
Enter your email address below to be informed every time a new article is posted at Stardeveloper.com:

You can follow Stardeveloper on Twitter
Article Categories
.NET  .NET
  ASP (16)
  ASP.NET (38)
  ADO (16)
  ADO.NET (10)
  COM (6)
  Web Services (4)
  C# (1)
  VB.NET (3)
  IIS (2)

J2EE  J2EE
  JSP (15)
  Servlets (9)
  Web Services (1)
  EJB (4)
  JDBC (4)
  E-Commerce (1)
  J2ME (1)
  Products (1)
  Applets (1)
  Patterns (1)
Log In
UserName Or Email:

Password:

Auto-Login:

Miscellaneous Links
  Submit Article

Hosted by Securewebs.com
 
Home : .NET : ASP : An ASP Tutorial to create your own Database driven Search Engine
 

An ASP Tutorial to create your own Database driven Search Engine
by Faisal Khan.

In this article I will guide you through the steps of creating a simple but effective search engine. We will divide our work into two steps :

  • Step 1 : Create a set of ASP pages to index the site content.
  • Step 2 : Create a search engine to offer keyword specific database dependent search to our visitors.

Requirements :

  • PWS / IIS
  • Microsoft Access Database

We will begin with creating a set of ASP pages to index the site content and then insert into the database. Here you will learn how easy it practically is to deal with databases in ASP. All statements of SQL select, insert, update and delete will come into play.

Boost your site's ranking through a search engine marketing plan that really works.

Creating HTML Form Page
We begin by creating an HTML Form page called 'addtodb.htm'. As it's name suggests you will use it to enter URLs of pages to index. So create a new HTML page and name it 'addtodb.htm' and then copy paste the following HTML code into it and then save it :

<html>
<head>
<style>
	body { font-family : Verdana; font-size : 8pt; }
	input { font-family : Verdana; font-size : 8pt;
height : 20; width : 250; }
</style>
</head>
<body>
Insert / Update File : ( using HTTP )
<form action="addtodb.asp">
<input type="text" name="look_for"><br>
<input type="submit" value="	" style="height : 17;
	width : 17;"> Submit ->
</form>
<br><br><br>
Insert / Update File : ( using FileSystemObject )
<form action="addtodb_fso.asp">
Base URL :-<br>
<input type="text" name="base_url"><br>
Absolute path to the File :-<br>
<input type="text" name="look_for"><br>
<input type="submit" value="	" style="height : 17;
	width : 17;"> Submit ->
</form>
<br><br><br>
Delete File :
<form action="delfromdb.asp">
<input type="text" name="del"><br>
<input type="submit" value="	" style="height : 17;
	width : 17;"> Submit ->
</form>
</body>
</html>

What does Form 1 do ?
As you might have guessed by seeing the code, it offer three Forms to site admin ( you ). The first one is used to enter complete URLs including HTTP ( e.g. http://www.stardeveloper.com/default.asp ). This Form will take you to 'addtodb.asp' page which will index the page using HTTP protocol. This is the easiest and most effective way to index pages. It enables you to index any of your site pages spanning across multiple hosts. It is also useful when title, description and keyword tags info in your pages is dynamically generated.

What does Form 2 do ?
The second Form instead of asking the complete URL ( like the first Form ), asks for base URL and absolute path to the page to index. This Form is optional. You should use it only when you cannot use HTTP protocol to index site pages ( more on that ). In the base URL field, you should enter the base URL of your site e.g. http://www.yoursite.com. And in the absolute path field, you should enter the absolute path to the page on your site e.g. /default.asp. This Form will lead to 'addtodb_fso.asp' page which indexes the pages using FileSystemObject. FileSystemObject is one of the scripting objects provided to you by ASP.

What does Form 3 do ?
The third Form asks for complete URL to the page e.g. http://www.stardeveloper.com/default.asp. You should use it when you want to delete a page entry in the database. Note this action will not delete the page, instead it will delete the indexed info of that page in the database. After this action that page will not be shown in the search engine.

Creating Access Database
Start Microsoft Access and create a new database 'directory.mdb'. Now create a table in the design view and name it 'all_pages'. Now put six fields in this table with 'id' field being the primary key. The names of the fields and their data types are shown in the image below :

all_pages Table
"all_pages" Table

Note if you are unsure or find it difficult, you can download the Access database discussed in this tutorial at the end. So stay cool.

Creating 'addtodb.asp' page
Open note pad or your favorite text editor and create a new page. Save it as 'addtodb.asp'. Now copy paste the following code into it :

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

 <%
  On Error Resume Next
  Dim geturl, title, description, keywords, strURL, strDB, con, results

   ' URL
   strURL = Request.QueryString("look_for")

   Set geturl = CreateObject("Stardeveloper.GetURL")
   strFileContents = geturl.Get(strURL)
   Set geturl = Nothing

   ' Keywords
   key1 = InStr(1, strFileContents, "<meta name=""keywords"" content=""", 1)
   key1 = key1 + Len("<meta name=""keywords"" content=""")
   key2 = InStr(key1, strFileContents, """>", 1)

   keywords = "," & Trim(Mid(strFileContents, key1, (key2 - key1))) & ","
   keywords = Replace (keywords, "'", " ")

   ' Description
   desc1 = InStr(1, strFileContents, "<meta name=""description"" content=""", 1)
   desc1 = desc1 + Len("<meta name=""description"" content=""")
   desc2 = InStr(desc1, strFileContents, """>", 1)

   description = Trim(Mid(strFileContents, desc1, (desc2 - desc1)))
   description = Replace (description, "'", " ")

   ' Title
   tit1 = InStr(1, lcase(strFileContents), "<title>", 1)
   tit1 = tit1 + Len("<title>")
   tit2 = InStr(tit1, strFileContents, "</title>", 1)

   title = Trim(Mid(strFileContents, tit1, (tit2 - tit1)))
   title = Replace (title, "'", " ")

   ' Our Connection Object
   Set con = CreateObject("ADODB.Connection")
   con.Open strDB
   Set results = con.Execute("select title, description, keywords _
         from all_pages where url = '" & strURL & "'")

   ' If the returning recordset is empty the add the URL with accompanying
   ' info to the database
   If results.EOF Then
     con.Execute("insert into all_pages (title, description, keywords, url, _
         mydate) values ('" & title & "', '" & description & "', '" & _
         keywords & "', '" & strURL & "', '" & date & "')")
     Set rs = con.Execute("select count(url) as total_count from all_pages")
     cnt = rs("total_count")
     Set rs = Nothing
     Response.Write "<b>New account successfully created for " & strURL & " _
         .</b>" & vbcrlf
     Response.Write "<br>"
     Response.Write "Total Pages Indexed : " & cnt & vbcrlf
   Else
   ' But if the returning recordset is not empty i.e. we have already added _
   ' title, desc, keywords etc into it then update that information with the _
   ' new one.
     con.Execute("update all_pages set title = '" & title & "', description = _
         '" & description & "', keywords = '" & keywords & "', mydate = #" _
         & date & "# where url = '" & strURL & "'")
     Response.Write "<b>Account updated successfully.</b>"
   End If

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

 %>
  </body></html>

 ( 5 Remaining ) Next

Comments/Questions ( Threads: 62, Comments: 118 )
    Contains 1 or more replies by the Author of this Article.
    Contains 1 or more replies by Faisal Khan.

  1. adovbs.inc
  2. geturl.dll
  3. Database error while inserting data thru ASP
  4. Work on server?
  5. Can't Delete Files from Database ( 4 Replies ) This thread contains 2 replies by the Author of this Article. This thread contains 2 replies by Faisal Khan.
  6. Uploading to a server ( 1 Reply ) This thread contains 1 reply by the Author of this Article. This thread contains 1 reply by Faisal Khan.
  7. NEED HELP - CREATING AN ASP SEARCH ENGINE ( 1 Reply )
  8. Search Engine Problem
  9. search engine troubleshoot ( 2 Replies ) This thread contains 1 reply by the Author of this Article. This thread contains 1 reply by Faisal Khan.
  10. How to 'index' within a database of 'url's in ASP
  11. Search.htm ( 1 Reply )
  12. no page is being displayed.
  13. The keywords, description and title is not showing up ( 1 Reply )
  14. Sorry, no matching record was found
  15. How to perform search with 3 input fields in a form?
  16. Upload File and Rename File and Save them (SQL+ASP)
  17. Switch to SQL?
  18. Keyword matching.Wildcard help
  19. How to equate a database record set value to a drop down list in asp ( 1 Reply )
  20. Updating Database with related tables using ASP
  21. Search form ( 1 Reply )
  22. Search Engine To Search A MS Access Database With MP3 Data ( 1 Reply )
  23. bad command or file name
  24. Awesome Tutorial...but How to make it crawl?
  25. search engine for a database? ( 1 Reply )
  26. ASP Search Engine ( 2 Replies ) This thread contains 1 reply by the Author of this Article. This thread contains 1 reply by Faisal Khan.
  27. Unable to add record to database
  28. geturl.dll żżżż !!!! :( ( 1 Reply ) This thread contains 1 reply by the Author of this Article. This thread contains 1 reply by Faisal Khan.
  29. getURL.dll ( 2 Replies ) This thread contains 1 reply by the Author of this Article. This thread contains 1 reply by Faisal Khan.
  30. Can selected results of the database be emailed?
  31. getURL.dll & windows 2003
  32. "Total pages indexed: 0" ( 1 Reply )
  33. Using Apache instead of IIS ( 1 Reply )
  34. Indexer will not add to database ( 3 Replies ) This thread contains 1 reply by the Author of this Article. This thread contains 1 reply by Faisal Khan.
  35. Nothing Shows!
  36. Multiple Search Fields ( 1 Reply )
  37. Adding sites
  38. License and support
  39. No pages are added
  40. a simple thing that confusing me ( 1 Reply ) This thread contains 1 reply by the Author of this Article. This thread contains 1 reply by Faisal Khan.
  41. Search Engine ( 1 Reply ) This thread contains 1 reply by the Author of this Article. This thread contains 1 reply by Faisal Khan.
  42. Need help with Select LIKE statement and % wildcard ( 1 Reply )
  43. wHAT IS no protocol ( 1 Reply ) This thread contains 1 reply by the Author of this Article. This thread contains 1 reply by Faisal Khan.
  44. problems linking search engine to database (using Access2K)
  45. Printing Border in crystal Report
  46. Dll Registered, Interface displays but no results ( 1 Reply ) This thread contains 1 reply by the Author of this Article. This thread contains 1 reply by Faisal Khan.
  47. How Could It Be Ordered By Number Of Keywords Found ?
  48. Ado Constants And More ...
  49. validating fileds in an access databse and displaying on a Intranet web page ( 2 Replies )
  50. title, keywords, description retrieval ( 1 Reply )
  51. search engine ( 3 Replies ) This thread contains 1 reply by the Author of this Article. This thread contains 1 reply by Faisal Khan.
  52. ASP query ( 1 Reply )
  53. Help On Creating Objects
  54. Cant make a replacement to GetURL :( ( 4 Replies ) This thread contains 1 reply by the Author of this Article. This thread contains 1 reply by Faisal Khan.
  55. Dedicated equivelent to html parser than GetURL ? ( 1 Reply ) This thread contains 1 reply by the Author of this Article. This thread contains 1 reply by Faisal Khan.
  56. GetURL Source Code ? ( 1 Reply ) This thread contains 1 reply by the Author of this Article. This thread contains 1 reply by Faisal Khan.
  57. search engine ( 1 Reply ) This thread contains 1 reply by the Author of this Article. This thread contains 1 reply by Faisal Khan.
  58. Unable to write to directory.mdb ( 4 Replies ) This thread contains 2 replies by the Author of this Article. This thread contains 2 replies by Faisal Khan.
  59. Image Search Engine ( 1 Reply ) This thread contains 1 reply by the Author of this Article. This thread contains 1 reply by Faisal Khan.
  60. addtodb hangs ( 1 Reply ) This thread contains 1 reply by the Author of this Article. This thread contains 1 reply by Faisal Khan.
  61. regsvr32 GetURL.dll ( 3 Replies ) This thread contains 1 reply by the Author of this Article. This thread contains 1 reply by Faisal Khan.
  62. Database driven Search Engine ---problems with inserting data ( 3 Replies ) This thread contains 2 replies by the Author of this Article. This thread contains 2 replies by Faisal Khan.

Post Comments/Questions

In order to post questions/comments, you must be logged-in. If you are not a member yet, then signup, otherwise login. Once you login then come back to this page and you'll see a form right here which will allow you to post comments/questions.

Please note, one of the benefits of signing up is to be notified immediately by email everytime you receive a reply to the thread you have subscribed.

 
© 1999 - 2009 Stardeveloper.com, All Rights Reserved.