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
Comment #2
ethan.han777 commentedComment #3
ethan.han777 commentedComment #4
jeroentPatch attached is the same patch as search_api_solr-suggestiongs-warning-message.diff, but I cleaned it up.
Comment #5
jeroentThis is the right patch.
Comment #7
drunken monkeyThanks 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
ifcondition parantheses) but otherwise it looks good.Committed. Thanks again!