Page 1 of 1

PHP search feature issues

Posted: Wed Jun 09, 2010 5:09 pm
by craigj1303
Hi All

I have just built a search feature for a furniture warehouse website i'm working on using PHP and a MYSQL database. The search performs a MYSQL query on a table containing a list of products. Here is the SQL:

Code: Select all

$query="SELECT * FROM products WHERE description LIKE '%" . $searchterm . "%' ";
Although the basic search works, there are a couple of things I need to work out how to do.

1) Plurals: For example, if I perform a search for "chair" the search returns all the rows in the products table that have the word "chair" in the description column. If I enter a search for "chai" or "hair" the search also returns all the chairs in the table. However, if I perform a search on "chairs" nothing comes up. How do I get the search to recognise this?

2) It seems that the search text has to be in the same order as the text in the database to return a result. e.g. if the description of the product in the database is "king size bed" the search will be successful if the user types "king size bed". However, if a search is entered for "bed king size" nothing is returned.

It is quite likely that people will search using plurals and type in words in random orders and I want to cover all the bases. I have scoured the net for solutions to this but have found nothing. I am hoping someone here can help, would really appreciate your feedback.

Thanks & Regards

Craig

Re: PHP search feature issues

Posted: Wed Jun 09, 2010 7:07 pm
by requinix
Look into FULLTEXT searches. This Zend article seems decent enough.