```Lou Vanek wrote:

> this was discussed on both this ML and the Rails ML about a week ago. The
> threads have the word 'fuzzy' in the subject.
>
> TomRossi7 wrote:
>
>> How would you recommend implementing something like a fuzzy search with
>> Ruby and a SQL database.  For example, I want to search a field in a
>> table for anything that is similar to "Frank Smithe".  I would want an
>> array of matches with some sort of score telling me how good of a match
>> the item received ("frank smithe" 100%, "frank smith" 90%).
>>
>> Am I making sense?  Is there a third party app I would need?
>>
>> Thanks,
>> Tom
>>
>>
>>
>
>
>
I needed to do something similar with my office database.  I used the
Levenshtein distance.  The routine was also
quite useful in finding name differences between my office data base and
the billing company's.
#------------------------------------------------------
# Determine Levenshtein distance of two strings

def Ld(s,t)

#s string #1
#t string #2

n = s.size
m = t.size
a = Array.new

if n != 0 && m != 0

#2 create array
r = Array.new
rz = Array.new

0.upto(m) {|x| r.push(0)}

0.upto(n) {|x|a.push(r.dup)}
a.each_index {|x| a[x][0] = x}
0.upto(m) {|x| a[0][x] = x}

cost =  0
1.upto(n) do |i|
1.upto(m) do |j|
if s[i] == t[j]
cost =0
else
cost = 1
end
a[i][j] = [a[ i- 1][j] +1,a[i][j - 1] + 1,a[i - 1][j -
1] + cost].min
end
end
a[n][m]
else
0
end
end

```