Signup · Login
Stardeveloper.com  
Home · Tutorials · Forums · Web Hosting Plans · Faisal Khan's Blog · Contact
Search Stardeveloper.com
Stardeveloper RSS Feed
Newsletter
Enter your email address below to be informed every time a new article is posted at Stardeveloper.com:

You can follow Faisal Khan on Twitter
Article Categories
.NET  .NET
  ASP (16)
  ASP.NET (41)
  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
 

Reviewing the code
We will now very quickly look into the code and see how it's done. Although this page might seem a bit long, but if you carefully look into it, all it contains are simple VBScript function calls and nothing more than that.

	<!--#include file="editme.asp"-->

This is first line of the page. All it does is to include 'editme.asp' file into this page. 'editme.asp' contains a single variable to store the relative location of the database. We will look into 'editme.asp' page later.

Reviewing the code :

<html>
<head>
	<style>
		body { font-family : Verdana; font-size : 8pt; }
	</style>
</head>
<body>

Above few lines are HTML tags with no ASP content.

	<%
		On Error Resume Next

Tells ASP script interpreter to continue with the next statement and not to stop if it receives an error during script execution. Actually it consists of two parts :

	On Error

By writing it we tell ASP script that we will receive the error and we will decide whether to stop the script from further execution ( by doing nothing ) or do some thing with it. On Error is an event which is fired when an error occurs in the execution of the script.

	Resume Next

By writing this we decide that we want ASP script interpreter to continue with the execution of the script and don't stop if it receives an error. This discussion has got a bit long, but it is very important that you understand what this statement does since you will be seeing it quite often in the ASP scripts, so you should be at ease with it. Tip, when you are testing your ASP code knock this line off, this will let you see the error and make corrections, but when you are releasing your ASP code then write this statement on top of your ASP page so that your script users might not see the errors if produced.

		Dim geturl, title, description, keywords, strURL
		Dim strDB, con, results

We define a list of variables which we will be using later in our script. Note in ASP all the variables are of type VARIANT, which means they can be of any type e.g. string ( text ), int ( number ), object etc.

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

strURL receives the URL which will be entered in the Form 1 of 'addtodb.htm' page. Since Form 1 had only one field with name 'look_for', we receive it's value by using this field name in the Request.QueryString method.

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

Now this is the real part to retrieve the contents of the page specified in the Form 1's 'look_for' field by using HTTP method. Note that ASP uses server side scripting languages to generate dynamic content, it is not possible to retrieve the contents of any page on the web using scripting languages. Scripting languages simply don't have that power. So what do we do ? we use our own component to retrieve the content of that web page using HTTP protocol. This is where ASP is very handy. It lets us use COM components to do tasks which we cannot do with simple VBScript. So with this search engine I am including my own Free component which can by used to retrieve page contents into a variable using HTTP protocol. All you have to do to use it can be seen by looking at the above three lines. Yes that's right, it is very simple to use. Just create an instance of it and then use it's only method Get() to get the page contents in a variable. Note that the only argument to Get() is strURL variable which is the URL of the page we want to retrieve.

As you might be knowing that in order to use a COM component on your computer ( or server ), you have to register it using regsvr32 command. So in order to use this component go to the DOS prompt and then move to the location of the directory where you have kept the search engine files. Now type the following command :

	regsvr32 GetURL.dll

And press enter. You will see a small window saying that component was successfully registered. That's it. Now you can use this component. Note, the ProgID of this component is Stardeveloper.GetURL.

   ' 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, "'", " ")

Since above three paragraphs of ASP script are similar we will discuss them together. All they do is to check the availability of certain HTML meta tags within that page. If you are familiar with HTML then you must be knowing about title, description and keyword meta tags. Above code looks for the presence of these meta tags in the contents of that page ( which is present in the strFileContents variable ). Note that earlier we retrieved all the contents of that page in the strFileContents variable, so we use this variable when we look for meta tags.

Since we are looking for meta tags to index their contents, make sure that title, description and keywords tags are present in the <head></head> section of your page which you want to index in the following manner :

<title>Your Page Title Goes Here</title>
<meta name="description" content="Your page description goes here">
<meta name="keywords" content="keyword1, keyword2, keyword3, keyword4 ...">

So our above ASP script indexed the contents of given web page and then retrieved the values of title, description and keywords tags in to title, description and keywords variables respectively.

Reviewing the code :

	' 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 & "'")

After populating the three variables title, description and keywords, we now move forward to add them to the database. We begin by creating Connection object. Then we open the database. Note as we discussed earlier, 'editme.asp' contains the location of the database in the variable strDB. So after including 'editme.asp' page in our 'addtodb.asp' page we can easily use the value of strDB in our script.

We then check the database to see if this given URL has been added to the database before. We do it by selecting title, description and keywords fields from the 'all_pages' table where URL is the given URL. If the returning recordset is empty then it shows that the URL has not been added to the database. But if the returning recordset is not empty then it means that URL has been added to the database before.

Reviewing the code
We will now very quickly look into the code and see how it's done. Although this page might seem a bit long, but if you carefully look into it, all it contains are simple VBScript function calls and nothing more than that.

	<!--#include file="editme.asp"-->

This is first line of the page. All it does is to include 'editme.asp' file into this page. 'editme.asp' contains a single variable to store the relative location of the database. We will look into 'editme.asp' page later.

Reviewing the code :

<html>
<head>
	<style>
		body { font-family : Verdana; font-size : 8pt; }
	</style>
</head>
<body>

Above few lines are HTML tags with no ASP content.

	<%
		On Error Resume Next

Tells ASP script interpreter to continue with the next statement and not to stop if it receives an error during script execution. Actually it consists of two parts :

	On Error

By writing it we tell ASP script that we will receive the error and we will decide whether to stop the script from further execution ( by doing nothing ) or do some thing with it. On Error is an event which is fired when an error occurs in the execution of the script.

	Resume Next

By writing this we decide that we want ASP script interpreter to continue with the execution of the script and don't stop if it receives an error. This discussion has got a bit long, but it is very important that you understand what this statement does since you will be seeing it quite often in the ASP scripts, so you should be at ease with it. Tip, when you are testing your ASP code knock this line off, this will let you see the error and make corrections, but when you are releasing your ASP code then write this statement on top of your ASP page so that your script users might not see the errors if produced.

		Dim geturl, title, description, keywords, strURL
		Dim strDB, con, results

We define a list of variables which we will be using later in our script. Note in ASP all the variables are of type VARIANT, which means they can be of any type e.g. string ( text ), int ( number ), object etc.

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

strURL receives the URL which will be entered in the Form 1 of 'addtodb.htm' page. Since Form 1 had only one field with name 'look_for', we receive it's value by using this field name in the Request.QueryString method.

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

Now this is the real part to retrieve the contents of the page specified in the Form 1's 'look_for' field by using HTTP method. Note that ASP uses server side scripting languages to generate dynamic content, it is not possible to retrieve the contents of any page on the web using scripting languages. Scripting languages simply don't have that power. So what do we do ? we use our own component to retrieve the content of that web page using HTTP protocol. This is where ASP is very handy. It lets us use COM components to do tasks which we cannot do with simple VBScript. So with this search engine I am including my own Free component which can by used to retrieve page contents into a variable using HTTP protocol. All you have to do to use it can be seen by looking at the above three lines. Yes that's right, it is very simple to use. Just create an instance of it and then use it's only method Get() to get the page contents in a variable. Note that the only argument to Get() is strURL variable which is the URL of the page we want to retrieve.

As you might be knowing that in order to use a COM component on your computer ( or server ), you have to register it using regsvr32 command. So in order to use this component go to the DOS prompt and then move to the location of the directory where you have kept the search engine files. Now type the following command :

	regsvr32 GetURL.dll

And press enter. You will see a small window saying that component was successfully registered. That's it. Now you can use this component. Note, the ProgID of this component is Stardeveloper.GetURL.

   ' 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, "'", " ")

Since above three paragraphs of ASP script are similar we will discuss them together. All they do is to check the availability of certain HTML meta tags within that page. If you are familiar with HTML then you must be knowing about title, description and keyword meta tags. Above code looks for the presence of these meta tags in the contents of that page ( which is present in the strFileContents variable ). Note that earlier we retrieved all the contents of that page in the strFileContents variable, so we use this variable when we look for meta tags.

Since we are looking for meta tags to index their contents, make sure that title, description and keywords tags are present in the <head></head> section of your page which you want to index in the following manner :

<title>Your Page Title Goes Here</title>
<meta name="description" content="Your page description goes here">
<meta name="keywords" content="keyword1, keyword2, keyword3, keyword4 ...">

So our above ASP script indexed the contents of given web page and then retrieved the values of title, description and keywords tags in to title, description and keywords variables respectively.

Reviewing the code :

	' 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 & "'")

After populating the three variables title, description and keywords, we now move forward to add them to the database. We begin by creating Connection object. Then we open the database. Note as we discussed earlier, 'editme.asp' contains the location of the database in the variable strDB. So after including 'editme.asp' page in our 'addtodb.asp' page we can easily use the value of strDB in our script.

We then check the database to see if this given URL has been added to the database before. We do it by selecting title, description and keywords fields from the 'all_pages' table where URL is the given URL. If the returning recordset is empty then it shows that the URL has not been added to the database. But if the returning recordset is not empty then it means that URL has been added to the database before.


Previous ( 1 Gone )( 4 Remaining ) Next

See all comments and questions (post-ad) posted for this tutorial.


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

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

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