nuvoleweb / search_api_spellcheck

Search api suggestions area for Drupal 8 views
2 stars 10 forks source link

Requires additional hook? #7

Open stanbellcom opened 6 years ago

stanbellcom commented 6 years ago

First of all, thank you for your contribution.

Secondly i have had some problems with this module and it only started working after i have added new hook in my custom module.

function MYMODULE_search_api_solr_query_alter(\Solarium\Core\Query\QueryInterface $solarium_query, \Drupal\search_api\Query\QueryInterface $query) {
  $solarium_query->addParam('spellcheck', 'on');
}

Is there something i missed while configuring it, or it does not work by itself?

Thirdly, are you planning to add it to contrib modules? The spelling suggestions is something many people might need.

DrColossos commented 5 years ago

Had the same issues, but solved it a little more complex, mainly because "spellcheck on" did not work at all

function MODULE_search_api_solr_converted_query_alter(\Solarium\QueryType\Select\Query\Query $solarium_query, \Drupal\search_api\Query\QueryInterface $query) {

    if( $query->getOption('search_api_spellcheck', FALSE) ) {
        $original_keys = $query->getOriginalQuery()->getKeys();

        if( empty($original_keys) ) {
            return;
        }

        array_pop($original_keys);
        $solarium_query->getSpellcheck()->setQuery(implode(' ', $original_keys));
        $solarium_query->getSpellcheck()->setCount(10);
        $solarium_query->getSpellcheck()->setOnlyMorePopular(true);
    }
}