Created
April 18, 2017 21:10
-
-
Save taylorbrooks/ba23cdaa7b1ad2147b683814111c3362 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
emails = Customer.select(:email).map(&:email) | |
emails.map do |email| | |
grouping = emails | |
.group_by{|em| Levenshtein.distance(email, em) } | |
.select {|k,v| k < 5 && != 0 } # ignore exact matches and ones far off | |
if !grouping.empty? | |
[email, grouping] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Assuming that the following is desired:
My guess is that the actual query would look something like this:
Then an AR version of it would be