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
https://forums.phpfreaks.com/topic/91997-did-you-mean-feature-in-search/
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.

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?

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.