finding similar matches
Moderator: General Moderators
- titaniumdoughnut
- Forum Commoner
- Posts: 33
- Joined: Wed Jul 13, 2005 2:02 pm
- Location: Manhattan
finding similar matches
Is there a way to query a MySQL database (through PHP) and ask it to use some kind of "similar matching" algorithms or something? I'm basically inventing terms for a technology I imagine might exist right now. Something that would search on a first and last name, and then present similar name combinations or variants of the names searched?
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
also look at the levenshtein() function as well as similar_text() and metaphone().
I've used the levenshtein() distance of two soundex() strings before, but it's expensive resource-wise.
MySQL supports soundex as well, which is nice, but I seem to remember there was some issue about the length of the resulting string or something...
metaphone() is supposedly better than soundex() but MySQL doesn't support it to my knowledge.
SOUNDEX in SQL is faster than php, IIRC. You'll likely want something like:
ok... I just went and looked it up. I did the above, then further ranked them by comparing the levenshtein() distances of the metaphone() of the two strings in PHP.
I've used the levenshtein() distance of two soundex() strings before, but it's expensive resource-wise.
MySQL supports soundex as well, which is nice, but I seem to remember there was some issue about the length of the resulting string or something...
metaphone() is supposedly better than soundex() but MySQL doesn't support it to my knowledge.
SOUNDEX in SQL is faster than php, IIRC. You'll likely want something like:
Code: Select all
SELECT * FROM table WHERE SUBSTRING(SOUNDEX(`haystack`),1,4) = SUBSTRING(SOUNDEX({$needle}),1,4)- titaniumdoughnut
- Forum Commoner
- Posts: 33
- Joined: Wed Jul 13, 2005 2:02 pm
- Location: Manhattan