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.
Comments