The term "search engine" groups a large category of tools. As their name tends to indicate, they all have one thing in common: they search for information from a set of data. There are a wide variety of search engines, ranging from massively powerful ones like Google to the smaller system we'll be creating in this chapter. Google uses around 10,000 computers all linked together. Our search engine will be made of some lines of HTML and PHP code running on our server. The set of data used is also not very comparable: Google has more than 2 billion entries, whereas a hotel with a hundred rooms is a pretty large hotel. Despite their differences, both of these systems implement the following common functionality:
How Does a SQL Search Engine Work?Here's a diagram showing how SQL search engines typically work, and this is the system we'll be following for our application:
The User InterfaceThe user interface (sometimes called UI) design is a very important part of the search engine design. Often web site designers focus on the query building, which is great, but the UI deserves special attention. The more complex you make it, the more information the user will be able to enter to feed the search engine, which might help them find a better result. However, an interface design that is too complex may make it harder to use. The UI part of the search engine is made up of an HTML page, which can either be a pure HTML page with no dynamically generated code or it can be HTML generated by some PHP code on the server.
Building the Query DynamicallyBy "building the query dynamically", I mean that the SQL query is never completely written in the PHP file. Instead, it is constructed "on the fly" each time a search is requested by the user. The code will analyze the input given by the user and insert it into the query.
Execution of the QueryOnce the query string has been built it needs to be executed, just like any other SQL query. We will use the PHP MySQL functions to send the query to the MySQL server for execution.
Building a List of the Matched ResultsThis stage is exactly the same as returning the results from a standard database query. We need to present a nicely formatted display of the results to the user. |