CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • API - Avoid search on email address
Pages: [1]

Author Topic: API - Avoid search on email address  (Read 870 times)

ToRum

  • I’m new here
  • *
  • Posts: 3
  • Karma: 0
  • CiviCRM version: 4.3
  • CMS version: Drupal
  • MySQL version: 5.5
  • PHP version: 5.3
API - Avoid search on email address
May 30, 2013, 01:41:05 am
Hi,

We are using the API to search for display_name. However the API is looking for string matches in both display name AND email addresses. I.e.:

$params = array(
  'version' => 3,
  'sequential' => 1,
  'display_name' => 'mysearch',
  'contact_type' => 'Organization',
  'rowCount' => 10,
  'return' => 'display_name',
);
$result = civicrm_api('Contact', 'get', $params);


In the results we find organizations that have "mysearch" only in their email address, not in their display_name. How to avoid this? We already tried to disable searching for Email Address on "Settings - Search Preferences" page, however without any succeed.

Thanks in advance!

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: API - Avoid search on email address
May 30, 2013, 01:56:38 am
Hi,

weird, not sure why it's doing it that way.

Try to search on organization_name (display name is a field that is generated from others (eg. first+last for individuals), it shouldn't touch email.




-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

ToRum

  • I’m new here
  • *
  • Posts: 3
  • Karma: 0
  • CiviCRM version: 4.3
  • CMS version: Drupal
  • MySQL version: 5.5
  • PHP version: 5.3
Re: API - Avoid search on email address
May 30, 2013, 02:55:28 am
Quote from: xavier on May 30, 2013, 01:56:38 am
Try to search on organization_name (display name is a field that is generated from others (eg. first+last for individuals), it shouldn't touch email.

If I try that, I get only full matches (value='mysearch' instead of value LIKE '%mysearch%'). Is there a way to tell the API to search for "containing matches" instead of "full/exact matches"? We want to use the API to find contacts (Individuals and Organisations) that match a certain string.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: API - Avoid search on email address
May 30, 2013, 03:59:26 am
you have to add the % manually,

mysearch% or '%mysearch% depending of what you want to search

on https://github.com/TechToThePeople/eu.tttp.qlookup what I've done is to do a mysearch% first, and only if I don't find enough I run an extra %mysearch%

I've implemented it as an api action (getttpquick) you can try using it see if it works for you or use the same technique

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

ToRum

  • I’m new here
  • *
  • Posts: 3
  • Karma: 0
  • CiviCRM version: 4.3
  • CMS version: Drupal
  • MySQL version: 5.5
  • PHP version: 5.3
Re: API - Avoid search on email address
May 31, 2013, 12:49:12 am
Thanks! Using %this works fine:

$params = array(
  'version' => 3,
  'sequential' => 1,
  'organization_name' => '%mysearch%',
  'contact_type' => 'Organization',
  'rowCount' => 10,
  'return' => 'display_name,organization_name',
);
$result = civicrm_api('Contact', 'get', $params);


I will have a look to eu.tttp.qlookup too, but for now we're on the road again ;-)

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • API - Avoid search on email address

This forum was archived on 2017-11-26.