I just posted this identical answer here for the question 'alter Suggestion box for apache solr autosearch' but am including at the question seems to be a duplicate:
Drupal 7's ApacheSolr module provides the following hook:
function hook_apachesolr_suggestions_alter(&$suggestions, $env_id)
In a custom module, if you implement
[my-custom-module-name]_apachesolr_suggestions_alter($suggestions, $env_id)
You can alter the suggestions array as follows:
function [my-custom-module-name]_apachesolr_suggestions_alter(&$suggestions, $env_id) {
foreach ($suggestions as $searchTerm) {
$replacement = $searchTerm->suggestion[0];
if ($searchTerm = 'test') {
$replacement = 'testing';
}
$suggestions[$searchTerm]->suggestion[0] = $replacement;
}
}
If you inspect the arrays via debugging, you'll see the following before your replacement code runs so you just need to alter what it suggests. In this case it was suggesting 'best' when searching for test, so the code above would replace 'best' with 'testing'. You'll probably want to do some optimization for error testing, but this gets you pretty far.
