Spellcheck functionality doesn't work as expected with SearchStax Solr connector

Created on 11 July 2025, 19 days ago

Setup

  • Solr version: 8.11
  • Drupal Core version: 10.4.8
  • Search API version: 8.x-1.38
  • Search API Solr version: 4.3.10
  • Configured Solr Connector: SearchStax Cloud with Token Auth

Issue

The Spellcheck "Did you mean" feature, which is part of the search_api_spellcheck module, doesn't seem to work with the SearchStax Solr connector.

On adding some logs, I've been able to trace it to the following file in Search API Solr module code:
web/modules/contrib/search_api_solr/src/SolrSpellcheckBackendTrait.php

It seems that the $result->getComponent method is returning null when trying to extract the "spellcheck" component from the API response. I also found that it works when I use the $result->getData() method to extract the raw data, and then write some custom logic to format the data according to what the search_api_spellcheck component expects to properly render the spellcheck suggestions.

I've attached a patch file with the changes I made, in case it is helpful for reference. I'm also sharing the steps to replicate my setup below, if someone wants to reproduce it on their own.

Steps to reproduce

  1. Create a Drupal app and connect to SearchStax.
  2. Install and enable the SearchStax module on Drupal.
  3. Also install and enable search_api, search_api_spellcheck, and search_api_solr for testing the "Did you mean" feature.
  4. Under Configuration > Search and metadata > SearchStax settings, check the boxes which say "Re-route searches through SearchStudio" and "Configure searches via SearchStudio". Make sure the "Spellcheck" option is selected
  5. Create a Search view connected to the SearchStax index, and populate content for testing. Add the Spellcheck Did you mean component in the headers and hit "Save".
  6. Index the data and enable Spellcheck on SearchStax Site Search dashboard by going to Basic Configurations > Spell check > Enable Spellcheck, set to "Dictionary driven" or "Data+Dictionary driven", then add a word in the dictionary and hit Save Draft and finally Publish.
  7. Go back to the Drupal Search view, and type in a misspelled word for the correct spelling you added to the Site Search dictionary. The "Did you mean" component won't show up in the header.

Hope this is enough information, but if not, please let me know and I'd be happy to share more details. Also, please feel free to modify any metadata as needed.

🐛 Bug report
Status

Active

Version

4.3

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @kaunaj
  • 🇦🇹Austria drunken monkey Vienna, Austria

    I didn’t see this in time and created a duplicate issue for this in the SearchStax module ( 🐛 Spellcheck not working Active ), sorry. The problem is that (if the user has selected that option) we want SearchStax to handle the spellcheck functionality and therefore remove the Spellcheck component from the Solarium query. However, Solarium apparently checks for that when parsing the response so we then don’t get the Spellcheck component in the response object even though there is a spellcheck key in the response JSON.

    I expect that that was a deliberate decision when writing the Solarium library so this is likely not gonna change. Therefore I thought the simplest solution would be to “trick” Solarium by re-adding the Spellcheck component after the search request was sent but before the response is actually parsed (\Solarium\Core\Query\Result\QueryType::parseResponse()).
    But if we could have a solution in Solarium or the Solr module that would of course be even better, it’s a bit hack-y this way.

Production build 0.71.5 2024