PHP search feature issues

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
craigj1303
Forum Newbie
Posts: 1
Joined: Wed Jun 09, 2010 5:06 pm

PHP search feature issues

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: PHP search feature issues

Post by requinix »

Look into FULLTEXT searches. This Zend article seems decent enough.
Post Reply