0

I need to search thru the name list and find out the relevant matched names with the matching percentage.For example, if i have the name list like,

Ramu
Rahim
Raju
Ravan
Mustafa

if i give the name like Raheem, it will find out the name Rahim and display the matching percentage like

Given Input:Raheem
Output:
Name Rahim match with the name Raheem 70%

Can i meet my requirement using MySql?

Note:I have tried with the FullText search in mysql,But that search match with only the words not by the characters

1

3 Answers 3

1

While it doesn't answer to your question directly, you may want to use Soundex or Metaphone.

Soundex is a phonetic algorithm for indexing names by sound, as pronounced in English.

5
  • 1
    Maybe he could make a fulltext field, which contains each name transformed to soundex word-by-word, which could be quickly searched, ex: instead of indexing Sir Arthur Conan Doyle, index S600 A636 C550 D400.
    – biziclop
    Mar 20, 2012 at 7:19
  • SOUNDEX also exsits for mysql: dev.mysql.com/doc/refman/5.0/en/… Mar 20, 2012 at 7:35
  • Maybe a trigger would be the best solution, which would do the soundex conversion for indexing.
    – biziclop
    Mar 20, 2012 at 7:36
  • Hi ,select SOUNDEX('Raheem'),select SOUNDEX('Rahim'),select SOUNDEX('Ram').All the three retutn the index R500.I think it somewhat vague on my concept.Is there any other idea? Mar 20, 2012 at 7:38
  • @MuneeswaranBalasubramanian Metaphone will return RHM, RHM, RM respectively. You can try it here
    – om-nom-nom
    Mar 20, 2012 at 7:42
0

there is a UDF for mysql, which you can find here: http://joshdrew.com/

look for: [2004-02-06] - MySQL Levenshtein Distance UDF

you can use the Levenshtein Distance to calc a percentage difference.

this could look like:

(min(length('hello'), length('hollo')) - LevDist('hello', 'hollo')) / min(length('hello'), length('hollo'))

3
  • Levenstein distance will tell you that Raheem and Rahim 3 symbols away. As far as Raheem and Hakeem.
    – om-nom-nom
    Mar 20, 2012 at 7:44
  • When i ll try i got the following error,mysqllevenshtein.cc:20:23: fatal error: my_global.h: No such file or directory compilation terminated. how can i resolve this and put into mysql? Mar 20, 2012 at 8:17
  • you also could use a stored procedure like this: supermind.org/blog/927/… Mar 20, 2012 at 8:22
0

Are you asking for an algorithm to compare the strings, or how to use such an algorithm in a sql query?

If you are asking the latter, create a user defined function that outputs the percentage based on 2 input strings, then select for every string in the table and filter where the percentage is above whatever threshold you are looking for.

So something like:

SELECT name, MyFuzzyStringComparer(name, @nameInQuestion) percentage 
FROM nameTable 
WHERE percentage > @threshold 
ORDER BY percentage

If you are looking for a comparison algorithm then the responses above seem to cover it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.