I'm using Search Api Solr to do programatic searches with the following example code. How can I include a proximity search with this approach? I'm looking through the code but I'm not seeing it.

I'm using geofield and the latlng is being indexed correctly by solr and can make a direct filter with it, but need proximity.

Any help would be great!

Current code:

$index = search_api_index_load('solr_index');
$query = $index->query();
$query->keys('My search term');

$filter = $query->createFilter('OR');
$filter->condition('field_my_field', 'value');
$query->filter($filter);
$results = $query->execute();

Comments

mrchristophy created an issue. See original summary.

drunken monkey’s picture

Status: Active » Fixed

See SearchApiViewsHandlerFilterLocation::query() – you want something like the following:

    $location_options = array();
    $location_options[] = array(
      'field' => 'field_location:latlon',// Field machine name
      'lat' => 16.54,
      'lon' => 48.16,
      'radius' => 10,// In km
    );
    $this->query->setOption('search_api_location', $location_options);
mrchristophy’s picture

It works, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.