Forum Moderators: coopster
You then split the search term into individual words, I would propose the explode function, using ' ' as the delimeter.
Next use each keyword to construct a simple regular expression that will return either an exact match, or a very close match.
If all keywords have an exact match, do not suggest. If one or more does not have an exact match, suggest the very near match.
So in pseudo-pseudocode we:
Get searchTerm
array keywords = explode(searchTerm, ' ')
array patterns = makeSimplePatterns(keywords)
array matches = findSuitableMatches(patterns, dictionary)
For each matches
If match == keyword
suggest = false
else
suggest = true
break out of for loop
end if
end for
newSearchTerm = implode(' ', matches)
suggestion = 'Did you mean: ' + newSearchTerm
search()
That isn't perfect, but might give you something to think about...
The function is a standard part of PHP [php.net].
If you have a dictionary of words, you can compare your word with the words in the list. The one which has the lowest levensthein value can be your search hint. Depending of the size of the dictionary and the speed of your server this may take noticable time though.