Building a Simple Search Engine

I recently wrote a small search engine to find stock symbols and found the exercise to be challenging and rewarding. I wrote most of the search functionality in PHP which, if you’re new to programming, is a good place to start. It is integrates smoothly with HTML, and it also has a readable, common-sense syntax.

The raw data consisted of three fields: The ticker symbol, the security name and the exchange.

I loaded this into the database with code rather than externally through any admin functions. Why? The fact is I struggled with the interface for a while (GoDaddy) and couldn’t get the data to load properly. Since it was not a big job anyway, I just wrote a small program to do it. For each row of data entered into the database it printed a confirmation line. In fact this served as a good warm-up to make sure I had a handle on database connections and basic MySQL code. 5.3 ls engine for sale

This was actually quite fun! I’d never loaded a large database onto an external server, and found it amazing to see how fast all of the data loaded. All 9000+ symbols loaded in less than 15 seconds.

Once the data was loaded, the question was: How do I get from a raw database full of stock names and symbols into a real search engine?

Well the first thing I had to do was to create an input box to get the user query.

So I started with a super-simple HTML page with a bare-bones user form with the kind of familiar input box used for anything from a Google search to a captcha confirmation. It takes the user information and calls another page called process_query.php.

Most of the “action” was to take place there.

Now, unlike the homepage which has the familiar html extension, the process_query page has the php extension. This essentially alerts the server (the computer which ‘serves’ the pages to your browser) to expect special php code.

Php sits on the page along with HTML code. Roughly speaking php extends the functionality of html, though of course is a fully functional language in its own right. A page with the php extension will properly display code written entirely in html. However with the php extension you have all of the power of php waiting at your fingertips. All you have to do is invoke to special compiler using the proper opening tag.

This is where all the fun starts!

Once the form from the home page invoked the process_query page, I had to deal with converting the raw values entered by the user into something the server could use. It turns out that this point of interaction between human and server can serve as a launch point for a lot of bugs and security issues. So I included several functions to scrub the values and make them safe and palatable to the server.

Leave a Reply

Your email address will not be published. Required fields are marked *