Jump to content

'did you mean' feature in search


synchro_irl

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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, '?';
}
?>

Link to comment
Share on other sites

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().

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.