Quote:
|
Originally Posted by RogerWilco
If my database has an entry for "Albertson" and the user types in "AlbertZson", "Albertsons", or some other variant, I would like a matching algorithm that would properly match.
|
Look up Soundex or (better) Metaphone.
What these algorithms do is reduce each word to the most important sounds. So similar vowel and consonant sounds (based on English phonics) are "normalized." It's a bit like doing a case-insensitive match by storing everything as upper case.
What you're trying to do entails this:
When you add a name, you'll add both the name and its hash in two separate columns. When you search for a name, you'll hash the name you're searching for and check that against the hash column.
Quote:
Ideally it would provide a match score as well. I would also like to use this to suggest several close variations if there isn't one obvious one.
I can pre-index my database if necessary.
FWIW, I'm currently using a MySQL database.
Thanks!
|
Match score: first, names that don't match Metaphone or Soundex are probably so far off you don't want to match them at all.
Nevertheless, there's an easy way: compare the actual values, and if they're equal give those a score of 1, otherwise 0.
The harder way: count the number of characters that are different. This is harder than it sounds because you have to do a "longest common subsequence" match to handle insertions and deletions. It's too much work for what you're trying to do, honestly, though perl (at least) has libraries that have that, and the Metaphone algorithm.
(Hint: hit search.cpan.org for Text::Metaphone and Algorithm:

iff)
Pre-index: yes, you'll need to maintain the hash column. If you're using MySQL 5, triggers could help you here.
(Completely irrelevant anecdote: I had been doing much the same thing and, by chance, had flown to California to go to the Mac Developer's conference. My brother lives in the area, and we went to a party with some friends of his in Oakland. So I'm talking to this woman and I mention how good Metaphone is. She says, "oh, wait, I have to get my husband." I'm a little baffled, but he comes back, and she asks me to say what I just did. Turns out the guy was Lawrence Phillips, who invented Metaphone...)