MySQL Search on TEXT field: words in any order

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
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

MySQL Search on TEXT field: words in any order

Post by simonmlewis »

Hello

I am sure I have posted this before but cannot find my post.

If a field contains "target gel", but someone searches for "gel target", in the usual:

Code: Select all

select * from table where name = '%$search%'
will not find the item.

I know there is a where with something like MATCH AGAINST, but I have tried and failed.
The fields being searched are set to TEXT.

How do you do it???
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: MySQL Search on TEXT field: words in any order

Post by s.dot »

Google for a "php fuzzy search"
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
pbs
Forum Contributor
Posts: 230
Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:

Re: MySQL Search on TEXT field: words in any order

Post by pbs »

You need to use MATCH ... AGAINST for your requirement.

For this your table type should be MYISAM and the searched field should have FULLTEXT index.
Post Reply