correcting misspelled words in a search input

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
Krabi
Forum Newbie
Posts: 2
Joined: Fri Mar 11, 2005 5:43 am

correcting misspelled words in a search input

Post by Krabi »

Hello,
I would like to optimize the search function on my website and implement a sort of correcting function for misspelled words.
If the string doesn't match any word in my mysql field, I begin to search "select * from mytable where field like '%_tring%'" and then s_ring, st_ing, etc... Then I search for %tring, s%ring, st%ing, etc...
Is this a good way to procede ? How can I make my script better ?
I've searched for tutorials or scripts-examples for functions like this with no results, if you know anything about this, I would really appreciate an answer!
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

WordNet

Post by anjanesh »

If you want a real good spell check you'll need a db containing words etc to do this efficiently.
You'll find an open source(? maybe just free) here :http://wordnet.princeton.edu/ but the MySQL conversion is done by another org : http://www.androidtech.com/html/wordnet-mysql-20.php
This way you can check and suggest like the way Google does.
Krabi
Forum Newbie
Posts: 2
Joined: Fri Mar 11, 2005 5:43 am

Post by Krabi »

Thank you, but the website I'm working on is in swedish, I don't think there are such dictionnairies available...
I can add that I'm searching in short fields, like film-titles.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

You can also try Pspell Functions - http://www.php.net/manual/en/ref.pspell.php
The only thing you need to get is pspell_config_data_dir -- location of language data files : http://www.php.net/manual/en/function.p ... ta-dir.php
Post Reply