4

Has anyone modified the default apachesolr 'did you mean?' suggestions that is returned out of the box with the apachesolr module?

For instance, a search for 'diabetes' currently returns 'did you mean: rates' http://www.health.govt.nz/search/results/diabetes

Is there a way to add some form of control over this, or is the solution simply adding more nodes to the index in the hopes of making it a better spell checker?

  • There are some configuration files in your search environment files in your server. I dont't know if you can do this with your solr Drupal client. – ram4nd Sep 5 '11 at 6:51
  • Correct, there are the standard schema.xml and SolrConfig.xml files that get copied over to Solr as a part of the install of the drupal apachesolr module. I would be looking to not modify these if I can as I do not want to maintain a patch for the module (makes tracking upstream harder) – wiifm Sep 5 '11 at 9:33
  • there are also protwords.txt, spellings.txt, stopwords.txt, synonyms.txt etc... – ram4nd Sep 5 '11 at 13:59
5

I found setting: <str name="spellcheck.onlyMorePopular">false</str>

(instead of true) in solrconfig.xml dramatically improved the quality of the spelling suggestions.

| improve this answer | |
0

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.

alter suggestion

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.