You are here

function handler_filter_radius::query in Search API Location 7

Add this filter to the query.

Due to the nature of fapi, the value and the operator have an unintended level of indirection. You will find them in $this->operator and $this->value respectively.

Overrides views_handler_filter::query

File

includes/handler_filter_radius.inc, line 157

Class

handler_filter_radius
Filter radius

Code

function query() {
  if (empty($this->value)) {
    return;
  }
  elseif (!isset($this->value[0]['locpick']['latitude']) || empty($this->value[0]['locpick']['latitude']) || !isset($this->value[0]['locpick']['longitude']) || empty($this->value[0]['locpick']['longitude']) || !isset($this->value[0]['distance']['search_distance']) || empty($this->value[0]['distance']['search_distance'])) {
    return;
  }
  $index = search_api_index_load(substr($this->table, 17));
  if (!isset($index) || !is_object($index) || !$index->enabled) {
    return;
  }
  $options = array_merge($this->options, $this->options['value'], $this->value[0]);

  //convering to miles (because localsolr search use only miles)
  $radius = $options['distance']['search_distance'] * 0.621371192237;
  $search_options = array(
    'query_type' => 'geo',
    'lat' => $options['locpick']['latitude'],
    'lng' => $options['locpick']['longitude'],
    'radius' => $radius,
    'sort' => 'asc',
  );
  $query = $this->query
    ->getSearchApiQuery();
  foreach ($search_options as $key => $value) {
    $query
      ->setOption($key, $value);
  }
  $old = $this->query
    ->getOriginalKeys();
  $keys =& $this->query
    ->getKeys();
  if ($old) {
    $keys =& $this->query
      ->getKeys();
    if (is_array($keys)) {
      $keys[] = $old;
    }
    elseif (is_array($old)) {

      // We don't support such nonsense.
    }
    else {
      $keys = "({$old}) ({$keys})";
    }
  }
}