hankknight
asked on
mySQL: Find most similar item
I want to find the item with the most similar characters as: 'foo'
So if these are the items:
green
food
money
pizza
the "food" should be returned.
So if these are the items:
green
food
money
pizza
the "food" should be returned.
select `NAME` from `organizations` where (NAME MOST SIMULAR TO FOO)
select `NAME` from `organizations` where name LIKE "foo"
Forgot to mention it :)
Forgot to mention it :)
I don't think LIKE is what you are thinking of.
LIKE would require you to use placeholders and it doesn't evaluate which is the best match.
You need to do this pro grammatically.
Look at Edit distance, Leventhstein distance, Smith-Waterman or similar solutions.
Try to find a data mining tool like Orange which includes text mining.
LIKE would require you to use placeholders and it doesn't evaluate which is the best match.
You need to do this pro grammatically.
Look at Edit distance, Leventhstein distance, Smith-Waterman or similar solutions.
Try to find a data mining tool like Orange which includes text mining.
ASKER
No, LIKE is not good enough.
I want the MOST simular match for foo.
So if these are the items:
green
boo
money
pizza
"boo" should be returned.
and:
green
fio
money
pizza
"fio" should be returned.
I want the MOST simular match for foo.
So if these are the items:
green
boo
money
pizza
"boo" should be returned.
and:
green
fio
money
pizza
"fio" should be returned.
E.g.:
PHP:
int levenshtein ( string $str1 , string $str2 );
returns the difference between the two strings.
If you do that for all strings in the table compared to the input string and take the result(s) with the smallest number you have the best match(es)
PHP:
int levenshtein ( string $str1 , string $str2 );
returns the difference between the two strings.
If you do that for all strings in the table compared to the input string and take the result(s) with the smallest number you have the best match(es)
ASKER
Is there anything like levenshtein available with pure sql ?
Not that I know of
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@tkalchev
I am also interested in how you would solve this in SQL.
May solve me lots of time ;)
Do you think this would work:
SELECT `NAME` from `organizations` where soundex(NAME) = soundex(foo) ??
Well apart from the limitations it sounds too good to be true.
I am also interested in how you would solve this in SQL.
May solve me lots of time ;)
Do you think this would work:
SELECT `NAME` from `organizations` where soundex(NAME) = soundex(foo) ??
Well apart from the limitations it sounds too good to be true.
Probably, just test it :)
You can find more info here.
Good luck