A method to suggest other names when user makes typos

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
guarriman
Forum Commoner
Posts: 44
Joined: Thu Nov 03, 2005 4:11 am

A method to suggest other names when user makes typos

Post by guarriman »

Hello.

Working with Apache+PHP+MySQL, I'm developing a website to allow users to find within a product catalog. Product info is stored within a MySQL table (ID, name, price).

These users usually make typos and mistakes when typing the product name, and I want to suggest them other names, similars to the typed one. For instance:
mp3 playr --> mp3 player

Does anybody know any algorithm or method to perform it? Thank you very much.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Code: Select all

select some_data from some_table where some_field sounds like 'mp3 playr';

or.....

select some_data from some_table where soundex(some_field) = soundex('mp3 playr');
Never used that syntax but a quick flick through the mysql manual sounds like it should work using the soundex algo :)
Post Reply