Generated this issue with the help of an LLM.
Problem/Motivation
Following up on 3119290, in views exposed string filters, limit the number of words found by `preg_match_all(static::WORDS_PATTERN, ' ' . $this->value, $matches, PREG_SET_ORDER)` for the `Contains any word` and `Contains all words` operators.
This should reduce query complexity and possibly open the door to removing the maxlength on the `` altogether.
Steps to reproduce
- Go to /admin/structure/views/settings and turn on Show the SQL query (under live preview settings).
- Edit the Content view (/admin/structure/views/view/content).
- Click the Title exposed filter, change the operator to Contains any word, and apply.
- In the preview's exposed Title field, enter a string of one-letter words up to the max length (256 characters): a b c d e f g h i j k l m n o p q r s t u v w x y z a b c ...
- Click Update preview and look at the SQL query below the preview.
- Actual result: the WHERE clause has about 128 node_field_data.title LIKE '%a%' conditions joined with OR. "Contains all words" gives the same thing joined with AND.
Expected result: the number of conditions is capped at a fixed word limit, whatever the input length.
Proposed resolution
In StringFilter::opContainsWord(), after the words are extracted with preg_match_all(static::WORDS_PATTERN, ...):
remove duplicate words, and only use the first 32? 16? words when building conditions.
Define N as a class constant (for example `StringFilter::MAX_WORDS`) so subclasses can override it.
Apply the same limit in `Combine::opContainsWord()`, which has its own copy of the word-splitting loop.
Add tests confirming that input with more than N words (and input with duplicates) produces at most N conditions, including when the value is set programmatically with setExposedInput() rather than through the exposed form.
Comments