synchro_irl Posted February 19, 2008 Share Posted February 19, 2008 hey guys im doing a website in php, and i already have a simple search feature, but i want to create a suggest search feature like in google, where if u misspell something, it will check a table for similar words and say 'did you mean' just like in google. whats involved in getting thos to work, with an existing piece of search code, which i am already using? thanks for the help in adance. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted February 19, 2008 Share Posted February 19, 2008 I would think the first step would be to just spell check the search and offer up the correct spelling as an alternative. Google also likely compares each of the search terms for similarities to other popular search terms as well, thus giving it the ability to match abbreviations and / or acronyms. Quote Link to comment Share on other sites More sharing options...
synchro_irl Posted February 19, 2008 Author Share Posted February 19, 2008 I would think the first step would be to just spell check the search and offer up the correct spelling as an alternative. Google also likely compares each of the search terms for similarities to other popular search terms as well, thus giving it the ability to match abbreviations and / or acronyms. ya exactly, spellcheck the word, thats what i wanna do. any ideas how i go about doing this? Quote Link to comment Share on other sites More sharing options...
Barand Posted February 19, 2008 Share Posted February 19, 2008 try <?php $data = array ( dog, goose, widget ); $search = 'widgget'; if ($i = array_search($search, $data)) { echo 'Found: ', $data[$i] , '<br/>'; } else { $other = 'something else'; foreach ($data as $item) { if (soundex($search) == soundex ($item)) { $other = $item; break; } } echo 'Did you mean ', $other, '?'; } ?> Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted February 19, 2008 Share Posted February 19, 2008 If you can obtain a list of dictionary words you can load them into a table. Then break apart the search terms and determine which ones have matching results in the table. The ones that don't have matching results are misspelled and you can find similar words with SOUNDEX(). Quote Link to comment Share on other sites More sharing options...
Barand Posted February 20, 2008 Share Posted February 20, 2008 If it's a database search, use ... WHERE column = '$search' first. If that doesn't find any, use ... WHERE column SOUNDS LIKE '$search' and use the found result/s in the "Did you mean .... ?" Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.