Searching articles for hand-picked keywords

The Search.asp SSI

The search form is a perfect candidate for a Server Side Include. The form can be included on a standalone search page, placed on the navigation bar, or even in a rotating banner. I implemented just one function, ProcessSearch( ). The framework of the function is shown below.

// ============================================
// display search form, bQuiet will suppress introductory text
// ============================================
function ProcessSearch ( bQuiet )
{
  // has the form been submitted?
  if ( Request.Form.Count )
  {
     // get data from form
     // perform search
     // display results
  }
  else
  {
     // explain search form
  }

  // display search form, even after search
  Out ( '<form action="Search.asp" method="post">' );
     Out ( '<input type="text" name="SearchText" size="20">' );
     Out ( '<input type="submit" value="Search">' );
  Out ( '</form>' );
}

This single function does everything - display the form, process the form, query the database and display the results. Just call ProcessSearch( ) from anywhere in your code, any it'll appear. In fact, I'll demonstrate...Use this form to search through the articles on CoverYourASP. You are searching through a database of keywords that I hand-picked for each page.

Please bear in mind that this is only the first stage of adding a search capability to the site - there is no way yet to search for "a AND b". If you enter multiple words I will return results that match any of them.

Tip: You don't have to type all of the words you're searching for - you can type "ad", not "advertising", or "appl" instead of "application variables".

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.

“Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.”