SimpleSearch Produces Error when searching for the word “calendar”

Summary

SimpleSearch Produces Error when searching for the word “calendar”

Step to reproduce

Enter “calendar” into search field

Searching for “cal” produces search results as expected. Anything more such as “cale…” produces the error.

“calendar pro” produces the error.

“calendar prog” or “calendar programs” does not produce the error.

No other search terms produce this error.

Observed behavior

This is the error message produced.

Fatal error: Uncaught ValueError: strpos(): Argument #3 ($offset) must be contained in argument
#1 ($haystack) in /home/ sxxxxxxx/public_html/core/components/simplesearch/src/SimpleSearch.php:454 Stack trace: #0 /home/ sxxxxxxx/public_html/core/components/simplesearch/src/SimpleSearch.php(454): strpos(‘Programs Calend…’, ’ ‘, 199) #1 /home/ sxxxxxxx/public_html/core/cache/includes/elements/modx/revolution/modsnippet/163.include.cache.php(89): SimpleSearch\SimpleSearch->createExtract(‘Programs Calend…’, 200, ‘calendar’, ‘…’)
#2 /home/ sxxxxxxx/public_html/core/src/Revolution/modScript.php(88): include(’/home/ sxxxxxxx/…‘)
#3 /home/ sxxxxxxx/public_html/core/src/Revolution/modParser.php(508): MODX\Revolution\modScript->process(NULL)
#4 /home/ sxxxxxxx/public_html/core/src/Revolution/modParser.php(221): MODX\Revolution\modParser->processTag(Array, true)
#5 /home/ sxxxxxxx/public_html/core/src/Revolution/modResource.php(521): MODX\Revolution\modParser->processElementTags(’', ‘…’, true, false, ‘[[’, ‘]]’, Array, 9)
#6 /home/ sxxxxxxx/public_html/core/src/Revolution/modResource.php(469): MODX\Revolution\modResource->parseContent()
#7 /home/ sxxxxxxx/public_html/core/src/Revolution/modResponse.php(72): MODX\Revolution\modResource->prepare()
#8 /home/ sxxxxxxx/public_html/core/src/Revolution/modRequest.php(154): MODX\Revolution\modResponse->outputContent(Array)
#9 /home/ sxxxxxxx/public_html/core/src/Revolution/modRequest.php(138): MODX\Revolution\modRequest->prepareResponse()
#10 /home/ sxxxxxxx/public_html/core/src/Revolution/modX.php(1499): MODX\Revolution\modRequest->handleRequest()
#11 /home/ sxxxxxxx/public_html/index.php(64): MODX\Revolution\modX->handleRequest()
#12 {main} thrown in /home/ sxxxxxxx/public_html/core/components/simplesearch/src/SimpleSearch.php on line 454

Expected behavior

This should produce a list of pages containing the word calendar.

Simple Search has been working flawlessly. I don’t know when this started. There is a page called calendar that works correctly without errors.

The Modx error log produces no related errors when this happens. There are some bad link tag errors that I haven’t been able to track down, but that occurs on other pages too. Otherwise the modx error log is clear when this happens.

Environment

Modx 3.0.4.
PHP 8.1.33
SimpleSearch 3.1.0-pl

This error is thrown when the code tries to create an extract from the text, and the length of the text is shorter than the desired length of the extract.

The code seems to throw an error for PHP 8 (when before it only logged a warning).

This path of the code only runs when the system setting use_multibyte is set to No. I guess this is the reason why you are the first to encounter the issue, as this value is usually set to Yes.

The simplest way to “fix” the issue would be to set the system setting use_multibyte to Yes (if that is possible).
Otherwise the code has to be changed, to check the length of the text before running strpos.

That was it! Thank you! I would never in a million years figured that out. :grinning_face:

I’ve updated the system settings to so that use_multibyte is set to yes. Now the search is working correctly.

Thank you so much!