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 (Moderator: Donald Lobo) »
  • Limiting API Proximity Search
Pages: [1]

Author Topic: Limiting API Proximity Search  (Read 1050 times)

bstalcup

  • I post occasionally
  • **
  • Posts: 47
  • Karma: 1
  • CiviCRM version: 4.7.3
  • CMS version: Joomla!
  • MySQL version: 5.5.36-cll-lve
  • PHP version: 5.3.29
Limiting API Proximity Search
February 21, 2014, 12:37:24 pm
Hello,

I've been working with the proximity search API, and I was wondering if it's possible to either
  • Increase the number of fields returned for each contact when doing a proximity search (right now it's just id, display_name, and contact_id), or
  • Further qualify the search, e.g. limiting to contacts who only have contact_type "Individual"

Thanks,
bstalcup

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Limiting API Proximity Search
February 23, 2014, 05:33:53 pm
Although nothing untested is officially supported (my stock line) the proximity search criteria are  probably available from contact.get

Contact.get accesses the same code as advanced search so generally if something is in advanced search it is somehow (& possibly unsupportedly) available from contact.get. I expect this bit of code is a clue as to what params work. (CRM_Contact_BAO_Query)

      case 'prox_distance':
        CRM_Contact_BAO_ProximityQuery::process($this, $values);
        return;

      case 'prox_street_address':
      case 'prox_city':
      case 'prox_postal_code':
      case 'prox_state_province_id':
      case 'prox_country_id':
        // handled by the proximity_distance clause
        return;

NB - if you are interested in writing a unit test to make this officially supported please say so! Happy to set yoy on the path
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

bstalcup

  • I post occasionally
  • **
  • Posts: 47
  • Karma: 1
  • CiviCRM version: 4.7.3
  • CMS version: Joomla!
  • MySQL version: 5.5.36-cll-lve
  • PHP version: 5.3.29
Re: Limiting API Proximity Search
February 24, 2014, 09:47:57 am
I got this to work, thanks!  I really appreciate the help.

So it seems right now (albeit "unsupported"), you can search for contacts via proximity to an address, zip code, country, etc. Are you aware of a way to bypass it and take it a step deeper and check for proximity to a certain Latitude-Longitude via contact.get?

It seems that is what's done on a lower level in the code (i.e. it converts a zip code/address/etc. to a lat-lng and compares that with the contacts' lat-lng in the database).  Do you know if there is a way to do such a request via contact.get?

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Limiting API Proximity Search
February 24, 2014, 11:38:37 am
 I think you would need to patch CRM_Contact_BAO_ProximityQuery::process or CRM_Contact_BAO_ProximityQuery::where (& add a unit test :-)) - probably skip this line

    $fnName = isset($config->geocodeMethod) ? $config->geocodeMethod : NULL;

if the prox_geocode_1 & prox_geocode_2 vars have been passed in & on CRM_Contact_BAO_Query you would need to add those fields in next to the other proximity fields
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

bstalcup

  • I post occasionally
  • **
  • Posts: 47
  • Karma: 1
  • CiviCRM version: 4.7.3
  • CMS version: Joomla!
  • MySQL version: 5.5.36-cll-lve
  • PHP version: 5.3.29
Re: Limiting API Proximity Search
February 24, 2014, 11:55:57 am
I apologize, but it seems I was mistaken.  I looked at the results I got from a test api call involving prox_distance, prox_distance_unit, and a postal code, and it just returned the contacts with a matching postal code to the one I provided

Here's the API call I made (thanks to the handy-dandy API Explorer):

Code: [Select]
/administrator/?option=com_civicrm
&task=civicrm/ajax/rest
&entity=Contact
&action=get
&debug=1
&sequential=1
&json=1
&prox_distance=10
&prox_distance_unit=miles
&postal_code=20147

However, when I changed the "prox_distance" from 10 to a much larger value, 1000 (which should certainly return many more contacts), I still get the same number of contacts, all of them whose postal code matches the one in the call.  I tried changing postal_code to prox_postal_code, and that didn't work either.  Any clue on how to potentially get this to work?  I feel like it's so close.

Thanks!
« Last Edit: February 24, 2014, 12:09:09 pm by bstalcup »

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Limiting API Proximity Search
February 24, 2014, 12:14:07 pm
try prox_postal_code rather than postal_code
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

bstalcup

  • I post occasionally
  • **
  • Posts: 47
  • Karma: 1
  • CiviCRM version: 4.7.3
  • CMS version: Joomla!
  • MySQL version: 5.5.36-cll-lve
  • PHP version: 5.3.29
Re: Limiting API Proximity Search
February 24, 2014, 12:15:15 pm
I tried that, but, unfortunately, it didn't work.

bstalcup

  • I post occasionally
  • **
  • Posts: 47
  • Karma: 1
  • CiviCRM version: 4.7.3
  • CMS version: Joomla!
  • MySQL version: 5.5.36-cll-lve
  • PHP version: 5.3.29
Re: Limiting API Proximity Search
February 26, 2014, 10:43:55 am
Any thoughts on where look next?

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Limiting API Proximity Search
February 26, 2014, 12:39:55 pm
I guess you would need to put some debug into CRM_Contact_BAO_ProximityQuery::process
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

bstalcup

  • I post occasionally
  • **
  • Posts: 47
  • Karma: 1
  • CiviCRM version: 4.7.3
  • CMS version: Joomla!
  • MySQL version: 5.5.36-cll-lve
  • PHP version: 5.3.29
Re: Limiting API Proximity Search
February 26, 2014, 12:41:13 pm
Alrighty, I'll do some digging and report back on what I find.

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Limiting API Proximity Search
February 26, 2014, 12:43:20 pm
Interestingly I just saw another forum post that implies there was some problem in this code from advanced search - they were saying they couldn't export from advanced search if they selected proximity distance in their criteria
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

bstalcup

  • I post occasionally
  • **
  • Posts: 47
  • Karma: 1
  • CiviCRM version: 4.7.3
  • CMS version: Joomla!
  • MySQL version: 5.5.36-cll-lve
  • PHP version: 5.3.29
Re: Limiting API Proximity Search
February 26, 2014, 12:54:35 pm
That IS interesting.  Perhaps they are related problems.  While I'm not too acquainted with the inner workings of the CiviCRM code, I will try my best :)

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Limiting API Proximity Search

This forum was archived on 2017-11-26.