2

I'm working on Drupal Version 7.22 and I'm trying to modify the results coming from Solr using the hook provided by the Solr Search Module.

The specific hook can be found here: http://drupalcontrib.org/api/drupal/contributions!search_api_solr!search_api_solr.api.php/function/hook_search_api_solr_search_results_alter/7

Here's how I implemented it from the module:

/** * Implements hook_search_api_solr_search_results_alter(). */ function zen_search_api_solr_search_results_alter(array &$results, SearchApiQueryInterface $query, Apache_Solr_Response $response){ $locations = array(); $rest = $results['results']; foreach($rest as $r){ $place = $r['fields']['field_business_name']; $postal_code = urlencode($r['fields']['field_business_address:postal_code']); $api = 'http://maps.googleapis.com/maps/api/geocode/json?address=' . $postal_code . '&sensor=false'; $api_results = file_get_contents($api); $data = json_decode($api_results, true); if($data['status'] == 'OK'){ $location = $data['results'][0]['geometry']['location']; $locations[] = array( 'place' => $place, 'lat' => $location['lat'], 'lng' => $location['lng'] ); } } $data = array('zen' => array('locations' => $locations)); drupal_add_js($data, 'setting'); } 

So basically what I'm trying to do here is to add the coordinates that I get from the Google maps Geo-coding API using drupal_add_js.

But I'm getting the following error:

Recoverable fatal error: Argument 3 passed to zen_search_api_solr_search_results_alter() must be an instance of Apache_Solr_Response, instance of stdClass given

Any ideas what's wrong here?

1 Answer 1

3

The problem was this one:

function zen_search_api_solr_search_results_alter(array &$results, SearchApiQueryInterface $query, Apache_Solr_Response $response){ ... } 

It should be this:

function zen_search_api_solr_search_results_alter(&$results, $query, $response){ ... } 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.