Search function....questions...

So I’m building a search function but I want to integrate something into the query that searches the database and presents options for misspellings…for example, if someone types in Tayler, but the correct spelling is Taylor it would still return the correct results, how do i do this?

Do I have to load in an API, or am i going to have a lot of coding on my hands tonight.

You could do this several ways

One way could be with mySQLs “SOUNDS LIKE” , using this I would run two queries (I think). First selecting the real matches for the search query (WHERE keyword = ‘Hog’), then running the SOUNDS LIKE query to fetch additional results. These should obviously be scored somehow so the user can have them presented based on how well they match.
[php]SELECT keyword
FROM test
WHERE keyword SOUNDS LIKE ‘Dogg’
OR keyword SOUNDS LIKE ‘Pawni’[/php]

Dog Pony

http://sqlfiddle.com/#!2/ded99/6

Other solutions may include a similar-words table. Perhaps you can register all searches and if a user searches for XYZ and then searches for XYY directly afterwards which leads to the user following a link, you could assume it’s a misspelling and add it to a misspellings table for review.

Thanks Jim! That sounds like a great idea! I’ll give it a shot and see how it comes out!

Sponsor our Newsletter | Privacy Policy | Terms of Service