Redundant Array check prevents Spellcheck with "Direct query" Parse Mode

Created on 16 May 2025, 4 months ago

Problem/Motivation

Problem

The getSpellcheckKeys() method in DidYouMeanSpellCheck.php throws an \InvalidArgumentException if the $keys parameter is not an array.
It means we can use any parse mode except "Direct query"

However, when the Search API's Parse Mode is set to "Single phrase", the $keys parameter can be an array with a '#conjunction' key and the actual search keys as its value.

This structure is similar to how the "Direct query" parse mode returns keys.

protected function getSpellcheckKeys($keys): array {
    if (!is_array($keys)) {
      throw new \InvalidArgumentException('The selected parse mode for fulltext fields is not compatible to Search API Spellcheck.');
    }

    // Filter out keyword that are negated.
    return array_filter(
      // Strip non-numeric array keys like '#collation'.
      array_filter($keys, 'is_int', ARRAY_FILTER_USE_KEY),
      'is_string'
    );
  }

"Direct query":

  public function parseInput($keys) {
    return $keys;
  }

"Single phrase":
return [
'#conjunction' => $this->getConjunction(),
$keys,
];

as you can see the '#conjunction' will be remove from array_filter.

Another problem: When an administrator selects the "Direct query" parse mode for a fulltext field, it can break all our search without any UI notifications.

Proposed resolution

Modify the getSpellcheckKeys() method to correctly handle the structure returned by the "Direct query" parse mode.
The \InvalidArgumentException should be removed or adjusted to only trigger in truly incompatible scenarios.

Feature request
Status

Active

Version

4.0

Component

Code

Created by

🇨🇦Canada man-1982

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024