Notice: Undefined property: stdClass::$suggestion in SearchApiSpellcheckSolr->__construct() (line 26 of /private/var/www/insight-platform/sites/all/modules/contrib/search_api_solr/includes/spellcheck.inc).
Warning: Invalid argument supplied for foreach() in SearchApiSpellcheckSolr->__construct() (line 26 of /private/var/www/insight-platform/sites/all/modules/contrib/search_api_solr/includes/spellcheck.inc).

Hi, I'm getting warning message above when I use hook__search_api_solr_search_results_alter() to re-excute the query with suggestion.
below is the code. (solr 4.x)

function mymodule_search_api_solr_search_results_alter(array &$results, SearchApiQueryInterface $query, $response) {  
  //if there's suggestion ...
  if (isset($response->spellcheck->suggestions->collation->collationQuery)) {
    //create a new query with the suggestion
    $collationQuery = str_replace("\"", "", $response->spellcheck->suggestions->collation->collationQuery);
    $collationQueryKeys = explode(" AND ", $collationQuery);
    $collationQueryKeys['#conjunction'] = 'AND';

    //regenerate result with new suggestion query
    $query->keys($collationQueryKeys);
    $collateResults = $query->execute();
    $results['results'] = $collateResults['results'];
    $results['result count'] = $collateResults['result count'];
  }
}

I also attached patch for this.

Comments

ethan.han777 created an issue. See original summary.

ethan.han777’s picture

Issue summary: View changes
ethan.han777’s picture

Issue summary: View changes
jeroent’s picture

Status: Active » Needs review
StatusFileSize
new761 bytes

Patch attached is the same patch as search_api_solr-suggestiongs-warning-message.diff, but I cleaned it up.

jeroent’s picture

StatusFileSize
new761 bytes

This is the right patch.

drunken monkey’s picture

Version: 7.x-1.8 » 7.x-1.x-dev
Status: Needs review » Fixed

Thanks for reporting this!
Your description sounds more like you're doing something wrong in your custom code. However, I guess a bit of defensive coding can't harm in any case. The patch still needed a bit of code style clean-up (spaces around the if condition parantheses) but otherwise it looks good.
Committed. Thanks again!

Status: Fixed » Closed (fixed)

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