Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,


I entered the value in a textbox if i give wrong spelling in the word i want to get the result from datbase which the closest matching to that search value



for example


Instead of Hyderabad is search for 'Hydearbad' which is wrong spelt i want to get suggestions from database only closest matching
Posted
Comments
Sanju Rao 12-Jul-14 8:35am    
you need to write your own algorithm for this there is no in build function. The auto complete functionality gives you the suggestions only if the characters starts matching. In your case if you use auto complete functionality with Hydearbad. auto complete function stops as soon as you reach the letter e and type r.
Sanju Rao 12-Jul-14 8:43am    
What I suggest is u can write algorithm. which divides the letter in matching and non matching characters. In your case match characters = "Hyde" and non match char = "arbad". Now get all the strings that match with "Hyde" and start matching recursively from the next char that are matching. If not match skip that match with next. The skipped should be given a rank value. keep proceeding in same way and the highest ranked vale will be your first string that is matching Hydearbad

Be aware that this is not trivial, not even slightly!
You are looking at implementing "Fuzzy Matching" which is not built in to SQL and is often implemented using the Levenshtein Distance algorithm[^] - there is an implementation of that here: http://www.kodyaz.com/articles/fuzzy-string-matching-using-levenshtein-distance-sql-server.aspx[^] and then ordering all "possible" strings by lowest LD value - the higher the LD, the more different two strings are.

Don't expect it to run quickly, and don't expect it to be simple to implement! :laugh:
 
Share this answer
 
Few years ago i asked similar question[^].
Please, visit it and find out the solution for you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900