I'm currently trying to enable spellcheck results with the search api. If I visit my apache solr server directly with http://myserver:8983/solr/d8/select?q=goood+worksd&spellcheck=true and provide the keywords and set spellcheck to true in the url parameters
I receive expected results
{ "response":{"numFound":0,"start":0,"docs":[] }, "spellcheck":{ "suggestions":[ "goood",{ "numFound":1, "startOffset":0, "endOffset":5, "suggestion":["good"]}, "worksd",{ "numFound":1, "startOffset":6, "endOffset":12, "suggestion":["worked"]}]}}
In the response I can see the spellcheck information I need in the spellcheck section.
However when I set the options programmatically before doing the query with the search api I don't receive any of this information.
$index_id = 'default_solr_index'; $index = \Drupal\search_api\Entity\Index::load($index_id); $query = $index->query(); $parse_mode = \Drupal::service('plugin.manager.search_api.parse_mode') ->createInstance('terms'); $parse_mode->setConjunction('AND'); $query->setParseMode($parse_mode); $query->keys($search_terms); $query->setFulltextFields(['title', 'body_field_parse', 'type','field_description','name','body','field_title','field_summary']); $query->addCondition('status', 1); $query->sort('search_api_relevance', 'DESC'); $query->setOption('spellcheck','true'); $executed_query = $query->execute(); var_dump($executed_query->getAllExtraData()); When I var_dump($executed_query->getAllExtraData()) all I get is
{ ["search_api_solr_response"]=> array(1) { ["response"]=> array(4) { ["numFound"]=> int(0) ["start"]=> int(0) ["maxScore"]=> float(0) ["docs"]=> array(0) { } } } }
I've done all kinds of variations giving true instead of 'true' and adding other options like
$query->setOption('spellcheck','true'); $query->setOption('spellcheck.build','true'); $query->setOption('search_api_spellcheck','true'); $query->setOption('spellcheck.extendedResults','true'); But nothing seems to work. I saw a spellcheck search api module someone posted but I couldn't get it to work and it seemed to do things very similar to how I'm doing it now. Is there a way to pass these parameters to my query to my apache solr? Or is my method correct and getAllExtraData not the proper way to get this information back?