Posted by wmostrey on December 6, 2010 at 10:44am
4 followers
| Project: | Apache Solr Multisite Search |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Issue Summary
Even when spellchecker and suggestions are enabled for apachesolr, they are not working for apachesolr_multisitesearch. You can also see this on drupal.org: it had suggestions before the redesign, but not anymore.
Comments
#1
This is a result of no form alter being done in the multisite module. Here's a copy-n-paste form alter that can be used for 6.x-2.x (note that this code is in the patch in #817702: Make compatible with apachesolr 2.x #11).
<?php
/**
* Implementation of hook_form_[form_id]_alter().
*
* This adds spelling suggestions, retain filters to the search form.
*/
function apachesolr_multisitesearch_form_search_form_alter(&$form, $form_state) {
if ($form['module']['#value'] == 'apachesolr_multisitesearch') {
$response = apachesolr_static_response_cache(NULL, 'apachesolr_multisitesearch');
if (variable_get('apachesolr_search_spellcheck', TRUE) && $response) {
// Get spellchecker suggestions into an array.
if (isset($response->spellcheck->suggestions) && $response->spellcheck->suggestions) {
$suggestions = get_object_vars($response->spellcheck->suggestions);
if ($suggestions) {
// Get the original query and replace words.
$query = apachesolr_current_query(NULL, 'apachesolr_multisitesearch');
foreach ($suggestions as $word => $value) {
$replacements[$word] = $value->suggestion[0];
}
$new_keywords = strtr($query->get_query_basic(), $replacements);
// Show only if suggestion is different than current query.
if ($query->get_query_basic() != $new_keywords) {
$form['basic']['suggestion'] = array(
'#prefix' => '<div class="spelling-suggestions">',
'#suffix' => '</div>',
'#type' => 'item',
'#title' => t('Did you mean'),
'#value' => l($new_keywords, $query->get_path($new_keywords)),
);
}
}
}
}
}
}
?>
#2
Marked duplicate of #817702: Make compatible with apachesolr 2.x
#3
Keeping open for 1.x, actually.
#4
Here's the patch, a straight port from the version that's true and tested in 6.2.
#5
Here is a patch that work with apachesolr 1.6