Doppel Build Status Gem Version Code Climate Dependency Status

Description

This acts_as extension provides the ability to find similar records matching a set of specified fuzzy matched fields.

Requirements

The database engine currently must impliment the levenshtein extension/feature. I believe this is currently limited to PostgreSQL.

Installation

In your Gemfile:

gem 'doppel'

Or, from the command line:

gem install doppel

Example

To use, call has_many_doppels method in the model:

class Company < ActiveRecord::Base
  has_many_doppels [:name]
end

[1] pry(main)> duplicates = Company.with_name_doppels
  Company Load (89586.2ms)  SELECT DISTINCT companies.* FROM companies, companies as doppel_companies WHERE (companies.id != doppel_companies.id) AND (levenshtein(companies.name, doppel_companies.name) < 2) GROUP BY companies.id HAVING COUNT(doppel_companies.id) > 0
  Company Load (89586.2ms)  SELECT DISTINCT companies.* FROM companies, companies as doppel_companies WHERE (companies.id != doppel_companies.id) AND (levenshtein(companies.name, doppel_companies.name) < 2) GROUP BY companies.id HAVING COUNT(doppel_companies.id) > 0
=> [#<Company:0x007fe486a84a18 id: 4332, type: "Company", name: "Basically Infinity", created_at: ..., updated_at: ... >,
 #<Company:0x007fe485e70010 id: 5179, type: "Company", name: "Stucco", created_at: ..., updated_at: ... >,
 #<Company:0x007fe485e6b5d8 id: 3234, type: "Company", name: "ÜSER", created_at: ..., updated_at: ... >,
 #<Company:0x007fe485e6aae8 id: 8456, type: "Company", name: "Orange", created_at: ..., updated_at: ... >]

 # From here you'll be able to do the following.

[2] pry(main)> duplicates.first.name_doppels
Company Load (13.1ms)  SELECT "companies".* FROM "companies" WHERE (levenshtein('Basically Infinity', companies.name) < 2) AND ("companies"."id" != $1)  [["id", 4332]]
  Company Load (13.1ms)  SELECT "companies".* FROM "companies" WHERE (levenshtein('Basically Infinity', companies.name) < 2) AND ("companies"."id" != $1)  [["id", 4332]]
=> [#<Company:0x007fe483464a00 id: 4057, type: "Company", name: "Interim Physicians", created_at: ..., updated_at: ... >]

Instance Methods Added To ActiveRecord Models

You'll have a number of methods added to each instance of the ActiveRecord model that to which doppel is added.

These depend on how has_many_doppels is configured. For each field that is supplied, you'll have

#{field_name}_doppels

in addition to

doppels

which will return any matching duplicates from all fields supplied.

The Future

Currently doppel only supports levenshtein text searching. I have tentative plans to impliment a more modular framework and support other field types such as dates or numerics.

Contributing to doppel

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
  • Fork the project
  • Start a feature/bugfix branch
  • Commit and push until you are happy with your contribution
  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
  • I would recommend using Rails 3.1.x and higher for testing the build before a pull request. The current test harness does not quite work with 3.0.x. The plugin itself works, but the issue lies with testing infrastructure.

Copyright (c) 2015 Dale Stevens, released under the MIT license