Full text search introduction

March 3rd, 2009

What is full text search?

Full text search is searching method that will use the entire words and find all match search against our database.

And according to Wikipedia

In text retrieval, full text search refers to a technique for searching a computer-stored document or database. In a full text search, the search engine examines all of the words in every stored document as it tries to match search words supplied by the user

In our traditional search method mostly we only search our criteria for against 1 column in our table.

Let’s say we have 1 million data about books, and we have title, author, and summary.

And now, we’re trying to create simple search against them. If I want to search book with title ‘PHP and MySQL Web Development’

forms01

We fill the form and click search button, and ta da, we got the result. But wait …

Here the problem, assuming that the code behind this search function is something like this :

Note : $q is value from our form.

    ...where title='$q'...

When the user didn’t know the title of the books, or just want to list books about PHP. We change the code to something like this :

    ...where title like '$q %' or title like '% $q %' or title like '% $q'...

Now, if I want to list books that related to PHP and MySQL, then our search will fail to meet our criteria. Assuming we enter ‘PHP and MySQL’ in our form.

That’s only a few problem in developing search function using SQL query functions.

Why should we use full text search?

Hmm, if you read this far, than you won’t ask why, right? Here the deal.

Most of full text search engine provide full text search capability, result weighting so you could rank the result based on criteria, and many more feature.

By now, most user are familiar enough with full text search (Google, Amazon), so why not building and putting an extra effort for our beloved user.

List of full text search engine

Related posts:

  1. Sphinx search introduction
  2. Submitting Form and Progressive Enhancement
  3. Codeigniter tutorial – To do list application
  4. CodeIgniter Tutorial – To do list application#2
  5. 101 PHP Tutorials for PHP Programmer Wannabe

One Comment