Drupal Answers Asked by Anamika on December 1, 2020
I want to restrict the suggestions for Apache Solr Search with hook_apachesolr_suggestions_alter(&$suggestions, $env_id)
. I have gone through the code and found the suggestion is prompt from apachesolr_autocomplete_suggest_word_completion()
called by a menu callback.
How can I override the suggestion block? I do not want to block indexing the words but just to hide them from suggestions.
Is there any hook available? Is hook_apachesolr_suggesstions_alter(&$suggestions,$env_id)
useful in this case?
I am using hook_apachesolr_querry_alter(DrupalSolrQueryInterface $query)
;
I want to skip the parameters from the query. Is there any way to do this?
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.
Answered by kbrinner on December 1, 2020
I was not able to find any hooks for the same. The alternate solution which I got is to implement hook_menu alter.
As apachesolr uses hook_menu() I altered the menu callback function.
Answered by Anamika on December 1, 2020
1 Asked on January 14, 2021 by cynthia
2 Asked on January 14, 2021 by spr
2 Asked on January 7, 2021 by selva
0 Asked on December 31, 2020 by jpsnow72
1 Asked on December 30, 2020 by dmk-i-t
1 Asked on December 30, 2020 by user1768942
2 Asked on December 28, 2020 by glenviewjeff
1 Asked on December 27, 2020 by laceysanderson
1 Asked on December 25, 2020 by richard-luckhurst
1 Asked on December 24, 2020 by hotwebmatter
1 Asked on December 23, 2020 by aryashree-pritikrishna
1 Asked on December 19, 2020 by robertsirwin
Get help from others!
Recent Questions
Recent Answers
© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP