Answers.Body: <p>It's coming from <a href="https://github.com/civicrm/civicrm-core/blob/5.16/CRM/Dedupe/BAO/Rule.php#L179" rel="nofollow noreferrer">line 179</a> in CRM/Dedupe/BAO/Rule.php, but it looks as if it's been like this forever so I'm not sure if there's a reason.</p>
  
  <p>If you change <a href="https://github.com/civicrm/civicrm-core/blob/5.16/CRM/Dedupe/BAO/Rule.php#L76" rel="nofollow noreferrer">line 76</a> where it sets <code>$on</code> to be the below code instead, it makes it work but I can't immediately see if that has any side-effects for other types of rules.</p>
  
  <pre><code>    $on = [
        "SUBSTR(t1.{$this-&gt;rule_field}, 1, {$this-&gt;rule_length}) = SUBSTR(t2.{$this-&gt;rule_field}, 1, {$this-&gt;rule_length})",
        "t1.{$this-&gt;rule_field} IS NOT NULL",
        "t1.{$this-&gt;rule_field} &lt;&gt; ''",
      ];
  </code></pre>
  
  <p>Note that dedupe checking caches results, so <strong>after you make that change clear cache</strong> at admin - system settings - cleanup caches.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-30T22:24:20.680Z
Answers.Text: Thank you for this - I wonder if there is a solution that does not involve changing core.
Answers.UserDisplayName: themak
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-30T22:47:16.827Z
Answers.Text: It might be possible to add these criteria via an extension with https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_dupeQuery.
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-08-10T06:17:14.593Z
Answers.LastActivityDate: 2019-08-10T06:17:14.593Z
Answers.UserDisplayName: Demerit
Body: <p>We have a custom field - 80% of our contacts have this custom field in their profile - the rest are blank.</p>
  
  <p>We setup a rule - if 7 characters or more of the custom filed are a match - it meets the threshold - however - contacts with blank custom fields are coming up as possible duplicates. Why is that?</p>
  
  <p>Latest Civi - Drupal 7.</p>
  
Tags: <duplicate-contacts>
Title: Dedupe Rule - blank matches
ThreadText: # Dedupe Rule - blank matches
  
  (Asked by: username_0 on 2019-08-07)
  
  We have a custom field - 80% of our contacts have this custom field in their profile - the rest are blank.
  
  We setup a rule - if 7 characters or more of the custom filed are a match - it meets the threshold - however - contacts with blank custom fields are coming up as possible duplicates. Why is that?
  
  Latest Civi - Drupal 7.
  
  **Tags:** duplicate-contacts
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-08-10. Score: 2 | Accepted answer
  
  It's coming from [line 179](https://github.com/civicrm/civicrm-core/blob/5.16/CRM/Dedupe/BAO/Rule.php#L179) in CRM/Dedupe/BAO/Rule.php, but it looks as if it's been like this forever so I'm not sure if there's a reason.
  
  If you change [line 76](https://github.com/civicrm/civicrm-core/blob/5.16/CRM/Dedupe/BAO/Rule.php#L76) where it sets `$on` to be the below code instead, it makes it work but I can't immediately see if that has any side-effects for other types of rules.
  
  ```
      $on = [
        "SUBSTR(t1.{$this->rule_field}, 1, {$this->rule_length}) = SUBSTR(t2.{$this->rule_field}, 1, {$this->rule_length})",
        "t1.{$this->rule_field} IS NOT NULL",
        "t1.{$this->rule_field} <> ''",
      ];
  
  ```
  
  Note that dedupe checking caches results, so **after you make that change clear cache** at admin - system settings - cleanup caches.
  
  > **Comments:**
  > **username_0**: Thank you for this - I wonder if there is a solution that does not involve changing core.  
  > **username_1**: It might be possible to add these criteria via an extension with https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_dupeQuery.  
  
  ---
  
  