Searching articles for hand-picked keywords

Querying the database

Having created the sSQLSearch SQL statement, let's search the database and display the results.

// open database connection
DBInitConnection ( );

// use static cursor to get record count
oRecordSet.Open ( 'SELECT URL,ShortDescr FROM ArticlePages WHERE ' + sSQLSearch, oConnection, adOpenStatic );

if ( !oRecordSet.EOF )
{
  var nCount = oRecordSet.RecordCount;

  Out ( 'I found ' + nCount + ' results matching "' + sSearch + '".<p>' );

  while ( !oRecordSet.EOF )
  {
     var sURL = '' + oRecordSet ( 0 );
     var sShortDescr = '' + oRecordSet ( 1 );

     Out ( '<a href="' + sURL + '">' + sShortDescr + '</a><br>' );

     oRecordSet.moveNext ( );
  }

  // release connection asap
  DBReleaseConnection ( );
}


The DB..( ) functions and the oConnection/oRecordSet objects are all defined in my Database.asp SSI. The code above shows a typical recordset loop, where you keep calling moveNext( ) until you have looped through all the records and reach End Of File (EOF).

That's the search. The only hard part was reading all those pages again, and deciding what you guys want to search for. There is always room for improvement of course - here are some things that I have on the list:

  • Allowing boolean expressions such as "(a OR b) AND (c or d)".
  • Storing keywords that were searched for in database.
  • Displaying common search expressions.

 

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“There are 10 types of people in the world, those who can read binary, and those who can't.”