tags:

views:

345

answers:

5

Hey Guys,

Creating a search function on my site using php/sql, simple enough - just using a SELECT ALL query on the database using the LIKE clause and echoing the result on the page. My question is, how can I add spelling suggestions in case the user mistyped their search query. Mysql doesn't return anything unless the search term matches exactly with the database content, e.g. "Dofs" will not return "Dogs". So how can spelling suggestions be added?

Thanks.

A: 

You need to check out something like the following:

http://phpir.com/spelling-correction

You will need a dictionary and the levenstien function basically.

Joe
A: 

in addition to Joe's excellent solution, you can make a soap call to provide alternate spellings (based on a search engine's language corpus)

Yahoo Spelling Suggestion: http://developer.yahoo.com/search/web/V1/spellingSuggestion.html

Google spelling request: http://code.google.com/apis/soapsearch/reference.html#1_3

jspcal
+1  A: 

What about PHP's pspell extension?

<?php
$pspell_link = pspell_new("en");

if (!pspell_check($pspell_link, "dofs")) {
    $suggestions = pspell_suggest($pspell_link, "dofs");

    foreach ($suggestions as $suggestion) {
        echo "Possible spelling: $suggestion<br />";
    }
}
?>

This PHP extension requires that you have aspell libraries installed.

Bill Karwin
A: 

Following you will find an excellent article by Peter Norvig on how to write a spell checker:

http://www.norvig.com/spell-correct.html

and the following two links are implementations in PHP of the code found in the article:

http://www.phpclasses.org/browse/package/4859.html http://soundofemotion.com/spellcorrect.txt

Hope this helps.

Waleed Al-Balooshi
A: 

i want spelling mistake suggestion script using php for search result

pradeepjangir