function apachesolr_multilingual_get_search_suggestions in Apache Solr Multilingual 6.3
Same name and namespace in other branches
- 7 apachesolr_multilingual.module \apachesolr_multilingual_get_search_suggestions()
Retrieve all of the suggestions that were given after a certain search Mostly copied from
Return value
array()
See also
apachesolrsearch_get_search_suggestions();
1 call to apachesolr_multilingual_get_search_suggestions()
- apachesolr_multilingual_apachesolr_search_page_alter in ./
apachesolr_multilingual.module - Modify the build array for any search output build by Apache Solr This includes core and custom pages and makes it very easy to modify both of them at once
File
- ./
apachesolr_multilingual.module, line 962 - Multilingual search using Apache Solr.
Code
function apachesolr_multilingual_get_search_suggestions($env_id, $filter_languages = array()) {
$suggestions_output = array();
if (apachesolr_has_searched($env_id)) {
$query = apachesolr_current_query($env_id);
$keyword = $query
->getParam('q');
$searcher = $query
->getSearcher();
$response = apachesolr_static_response_cache($searcher);
$language_ids = array_keys(apachesolr_multilingual_language_list());
// Get spellchecker suggestions into an array.
foreach ($language_ids as $language_id) {
if (!empty($filter_languages) && !in_array($language_id, $filter_languages)) {
continue;
}
if (!empty($response->{'spellcheck_' . $language_id}->suggestions)) {
$suggestions = get_object_vars($response->{'spellcheck_' . $language_id}->suggestions);
if ($suggestions) {
$replacements = array();
// Get the original query and retrieve all words with suggestions.
foreach ($suggestions as $word => $value) {
$replacements[$word] = $value->suggestion[0];
}
// Replace the keyword with the suggested keyword.
$suggested_keyword = strtr($keyword, $replacements);
// Show only if suggestion is different than current query.
if ($keyword != $suggested_keyword) {
$suggestions_output[$language_id] = $suggested_keyword;
}
}
}
}
}
return $suggestions_output;
}