Online Spell Checker…

This can be viewed online on my Social Search site Sansj.com. try searching for Yahoi Search.
It is a good thing have a spell checker facility in a Search Engine, people are not always correct with their spelling and yeah sometimes typos do occur. I read somewhere about using a statistical model to develop a spell checker, and, I was amazed. But I had neither the time or the brain to implement/optimize it,so I went for the easier option, I used yahho spell checker api available here.The code I came up with (with some help from my previous work and also a few other work available on the internet) is presented here:

//COPY PASTING WILL NOT WORK, UNLESS, YOU ARE WILLING TO CHANGE THE QUOTES
$req_spcheck=’http://search.yahooapis.com/WebSearchService/V1/spellingSuggestion?appid=YOURIDGOESHERE&query=YOURQUERY&results=3&output=php’; ///create the query here, output is serialized PHP
$checked=”;
$res = file_get_contents($req_spcheck);
$phpobj_spcheck = unserialize($res);
$key2=0;
foreach($phpobj_spcheck as $arr2) { ///for each loop to get each of the suggestions
$key2++;
$checked.='<a href=”http://trk7.com/ask/mysearch2.php?sstring=’.trim(urlencode($arr2[‘Result’])).’&submit=&co=all”>’.($arr2[‘Result’]).'</a>’; ///create a link that can be used also as a search query on my site
$str4=$arr2[‘Result’];
}
if ($str4!=””){ //making sure we r getting a corrected result
echo “<div style=’font-size:1.2em;background-color:#FFFFCC;border-top:1px solid gold;border-bottom:2px solid gold;text-align:left’><img src=’images/spellcheck.png’ style=’padding-right:2px’ alt=’Spellitrite ‘ />Did you mean:”.$checked.”?</div>”; ///display the spell suggestions
}

This can be viewed online on my Social Search site Sansj.com. try searching for Yahoi Search.

Totally Cool.
P.S. Should have known that, to display code in wordress, should have used htmlentities.Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *