When a Search API search view is used (search is performed), the following error is thrown in the drupal log:

Warning: count(): Parameter must be an array or an object that implements Countable in Drupal\search_api\Plugin\search_api\processor\Highlight->highlightField() (line 625 of search_api/src/Plugin/search_api/processor/Highlight.php)

PHP version we use on this website where this error occurs is 7.3.15. The search still works, but this error is thrown on every search and on high traffic websites this can quickly flood the logs.

Comments

Klemen Pevec created an issue. See original summary.

klemendev’s picture

This issue can be fixed by setting Highlight returned field data parameter from Always to If the server returns fields.

I am not sure if this is meant to be this way or not so I am leaving this ticket open for one of the developers to confirm if this is normal or not.

drunken monkey’s picture

Component: General code » Plugins
Status: Active » Needs review
StatusFileSize
new1.38 KB

Very strange, this seems to indicate a failure in the regular expression evaluation.
The attached patch should both detect this problem and add a more helpful log message for the problem. (Which, admittedly, will still flood your logs, I guess.) Could you please try it and tell me what it says? (Or whether it doesn’t work at all?)

klemendev’s picture

I have changed the configuration of the search engine quite a lot from the time of reporting this bug and this is no longer happening, unfortunately.

pcate’s picture

I've been seeing this error in our logs as well. Here's a stack trace from new relic:

NoticedError: Warning: count(): Parameter must be an array or an object that implements Countable in Drupal\search_api\Plugin\search_api\processor\Highlight->highlightField() (line 625 of /mnt/www/html/REDACTED/docroot/modules/contrib/search_api/src/Plugin/search_api/processor/Highlight.php) #0 /mnt/www/html/REDACTED/docroot/core/includes/bootstrap.inc(600): _drupal_error_handler_real(2, 'count(): Parame...', '/mnt/www/html/h...', 625, Array) #1 [internal function]: _drupal_error_handler(2, 'count(): Parame...', '/mnt/www/html/h...', 625, Array) #2 /mnt/www/html/REDACTED/docroot/modules/contrib/search_api/src/Plugin/search_api/processor/Highlight.php(625): count(false) #3 /mnt/www/html/REDACTED/docroot/modules/contrib/search_api/src/Plugin/search_api/processor/Highlight.php(328): Drupal\search_api\Plugin\search_api\processor\Highlight->highlightField('Fiscal Year 201...', Array) #4 /mnt/www/html/REDACTED/docroot/modules/contrib/search_api/src/Plugin/search_api/processor/Highlight.php(254): Drupal\search_api\Plugin\search_api\processor\Highlight->highlightFields(Array, Array) #5 /mnt/www/html/REDACTED/docroot/modules/contrib/search_api/src/Entity/Index.php(675): Drupal\search_api\Plugin\search_api\processor\Highlight->postprocessSearchResults(Object(Drupal\search_api\Query\ResultSet)) #6 /mnt/www/html/REDACTED/docroot/modules/contrib/search_api/src/Query/Query.php(606): Drupal\search_api\Entity\Index->postprocessSearchResults(Object(Drupal\search_api\Query\ResultSet)) #7 /mnt/www/html/REDACTED/docroot/modules/contrib/search_api/src/Query/Query.php(538): Drupal\search_api\Query\Query->postExecute() #8 /mnt/www/html/REDACTED/docroot/modules/contrib/search_api/src/Plugin/views/query/SearchApiQuery.php(573): Drupal\search_api\Query\Query->execute() #9 /mnt/www/html/REDACTED/docroot/core/modules/views/src/ViewExecutable.php(1426): Drupal\search_api\Plugin\views\query\SearchApiQuery->execute(Object(Drupal\views\ViewExecutable)) #10 /mnt/www/html/REDACTED/docroot/core/modules/views/src/ViewExecutable.php(1454): Drupal\views\ViewExecutable->execute(NULL) #11 /mnt/www/html/REDACTED/docroot/core/modules/views/src/Plugin/views/display/Block.php(138): Drupal\views\ViewExecutable->render() #12 /mnt/www/html/REDACTED/docroot/core/modules/views/src/ViewExecutable.php(1630): Drupal\views\Plugin\views\display\Block->execute() #13 /mnt/www/html/REDACTED/docroot/core/modules/views/src/Element/View.php(77): Drupal\views\ViewExecutable->executeDisplay('site_search_blo...', Array) #14 /mnt/www/html/REDACTED/docroot/core/modules/views/src/Plugin/Block/ViewsBlock.php(59): Drupal\views\Element\View::preRenderViewElement(Array) #15 /mnt/www/html/REDACTED/docroot/core/modules/layout_builder/src/EventSubscriber/BlockComponentRenderArray.php(105): Drupal\views\Plugin\Block\ViewsBlock->build() #16 [internal function]: Drupal\layout_builder\EventSubscriber\BlockComponentRenderArray->onBuildRender(Object(Drupal\layout_builder\Event\SectionComponentBuildRenderArrayEvent), 'section_compone...', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher)) #17 /mnt/www/html/REDACTED/docroot/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func(Array, Object(Drupal\layout_builder\Event\SectionComponentBuildRenderArrayEvent), 'section_compone...', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher)) #18 /mnt/www/html/REDACTED/docroot/core/modules/layout_builder/src/SectionComponent.php(113): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('section_compone...', Object(Drupal\layout_builder\Event\SectionComponentBuildRenderArrayEvent)) #19 /mnt/www/html/REDACTED/docroot/core/modules/layout_builder/src/Section.php(86): Drupal\layout_builder\SectionComponent->toRenderArray(Array, false) #20 /mnt/www/html/REDACTED/docroot/core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php(317): Drupal\layout_builder\Section->toRenderArray(Array) #21 /mnt/www/html/REDACTED/docroot/core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php(276): Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay->buildSections(Objec
in newrelic_notice_error called at /mnt/www/html/REDACTED/docroot/modules/contrib/new_relic_rpm/src/ExtensionAdapter/ExtensionAdapter.php (37)
in Drupal\new_relic_rpm\ExtensionAdapter\ExtensionAdapter::logError called at /mnt/www/html/REDACTED/docroot/modules/contrib/new_relic_rpm/src/Logger/NewRelicLogger.php (130)
in Drupal\new_relic_rpm\Logger\NewRelicLogger::log called at /mnt/www/html/REDACTED/docroot/core/lib/Drupal/Core/Logger/LoggerChannel.php (127)
in Drupal\Core\Logger\LoggerChannel::log called at /mnt/www/html/REDACTED/docroot/core/includes/errors.inc (170)
in _drupal_log_error called at /mnt/www/html/REDACTED/docroot/core/includes/errors.inc (85)
in _drupal_error_handler_real called at /mnt/www/html/REDACTED/docroot/core/includes/bootstrap.inc (600)
in _drupal_error_handler called at ? (?)
in count called at /mnt/www/html/REDACTED/docroot/modules/contrib/search_api/src/Plugin/search_api/processor/Highlight.php (625)
in Drupal\search_api\Plugin\search_api\processor\Highlight::highlightField called at /mnt/www/html/REDACTED/docroot/modules/contrib/search_api/src/Plugin/search_api/processor/Highlight.php (328)
in Drupal\search_api\Plugin\search_api\processor\Highlight::highlightFields called at /mnt/www/html/REDACTED/docroot/modules/contrib/search_api/src/Plugin/search_api/processor/Highlight.php (254)
in Drupal\search_api\Plugin\search_api\processor\Highlight::postprocessSearchResults called at /mnt/www/html/REDACTED/docroot/modules/contrib/search_api/src/Entity/Index.php (675)
in Drupal\search_api\Entity\Index::postprocessSearchResults called at /mnt/www/html/REDACTED/docroot/modules/contrib/search_api/src/Query/Query.php (606)
in Drupal\search_api\Query\Query::postExecute called at /mnt/www/html/REDACTED/docroot/modules/contrib/search_api/src/Query/Query.php (538)
in Drupal\search_api\Query\Query::execute called at /mnt/www/html/REDACTED/docroot/modules/contrib/search_api/src/Plugin/views/query/SearchApiQuery.php (573)
in Drupal\search_api\Plugin\views\query\SearchApiQuery::execute called at /mnt/www/html/REDACTED/docroot/core/modules/views/src/ViewExecutable.php (1426)
in Drupal\views\ViewExecutable::execute called at /mnt/www/html/REDACTED/docroot/core/modules/views/src/ViewExecutable.php (1454)
in Drupal\views\ViewExecutable::render called at /mnt/www/html/REDACTED/docroot/core/modules/views/src/Plugin/views/display/Block.php (138)
in Drupal\views\Plugin\views\display\Block::execute called at /mnt/www/html/REDACTED/docroot/core/modules/views/src/ViewExecutable.php (1630)
in Drupal\views\ViewExecutable::executeDisplay called at /mnt/www/html/REDACTED/docroot/core/modules/views/src/Element/View.php (77)
in Drupal\views\Element\View::preRenderViewElement called at /mnt/www/html/REDACTED/docroot/core/modules/views/src/Plugin/Block/ViewsBlock.php (59)
drunken monkey’s picture

Thanks a lot for chiming in, PCate! Unfortunately, the stack trace doesn’t really bring any extra information here. Could you tell me what happens when you apply the patch, what message you get in your logs then?

drunken monkey’s picture

Status: Needs review » Fixed

OK, then let’s just commit and see the error message when someone files a bug report for it. ;)

  • drunken monkey committed c530763 on 8.x-1.x
    Issue #3115343 by drunken monkey: Fixed warning in Highlight processor...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

odai atieh’s picture

I have the same issue, and you can find more info in the below:
Message: A PCRE error (#2) occurred during results highlighting.

#32 /modules/contrib/search_api/src/Plugin/search_api/processor/Highlight.php(634): Drupal\search_api\Plugin\search_api\processor\Highlight::highlightField
#31 /modules/contrib/search_api/src/Plugin/search_api/processor/Highlight.php(330): Drupal\search_api\Plugin\search_api\processor\Highlight::highlightFields
#30 /modules/contrib/search_api/src/Plugin/search_api/processor/Highlight.php(256): Drupal\search_api\Plugin\search_api\processor\Highlight::postprocessSearchResults
#29 /modules/contrib/search_api/src/Entity/Index.php(675): Drupal\search_api\Entity\Index::postprocessSearchResults
#28 /modules/contrib/search_api/src/Query/Query.php(610): Drupal\search_api\Query\Query::postExecute
#27 /modules/contrib/search_api/src/Query/Query.php(542): Drupal\search_api\Query\Query::execute
#26 /modules/contrib/search_api/src/Plugin/views/query/SearchApiQuery.php(581): Drupal\search_api\Plugin\views\query\SearchApiQuery::execute
#25 /core/modules/views/src/ViewExecutable.php(1426): Drupal\views\ViewExecutable::execute
#24 /core/modules/views/src/ViewExecutable.php(1454): Drupal\views\ViewExecutable::render
#23 /core/modules/views/src/Plugin/views/display/Page.php(183): Drupal\views\Plugin\views\display\Page::execute
#22 /core/modules/views/src/ViewExecutable.php(1630): Drupal\views\ViewExecutable::executeDisplay
#21 /core/modules/views/src/Element/View.php(81): Drupal\views\Element\View::preRenderViewElement
#20 [internal](0): call_user_func_array
#19 /core/lib/Drupal/Core/Security/DoTrustedCallbackTrait.php(101): Drupal\Core\Render\Renderer::doTrustedCallback
#18 /core/lib/Drupal/Core/Render/Renderer.php(786): Drupal\Core\Render\Renderer::doCallback
#17 /core/lib/Drupal/Core/Render/Renderer.php(377): Drupal\Core\Render\Renderer::doRender
#16 /core/lib/Drupal/Core/Render/Renderer.php(201): Drupal\Core\Render\Renderer::render
#15 /core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(241): Drupal\Core\Render\MainContent\HtmlRenderer::Drupal\Core\Render\MainContent\{closure}
#14 /core/lib/Drupal/Core/Render/Renderer.php(578): Drupal\Core\Render\Renderer::executeInRenderContext
#13 /core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(242): Drupal\Core\Render\MainContent\HtmlRenderer::prepare
#12 /core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(132): Drupal\Core\Render\MainContent\HtmlRenderer::renderResponse
#11 /core/lib/Drupal/Core/EventSubscriber/MainContentViewSubscriber.php(90): Drupal\Core\EventSubscriber\MainContentViewSubscriber::onViewRenderArray
#10 [internal](0): call_user_func
#9 /core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(142): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher::dispatch
#8 /app/vendor/symfony/http-kernel/HttpKernel.php(163): Symfony\Component\HttpKernel\HttpKernel::handleRaw
#7 /app/vendor/symfony/http-kernel/HttpKernel.php(80): Symfony\Component\HttpKernel\HttpKernel::handle
#6 /core/lib/Drupal/Core/StackMiddleware/Session.php(57): Drupal\Core\StackMiddleware\Session::handle
#5 /core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\KernelPreHandle::handle
#4 /core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\Core\StackMiddleware\ReverseProxyMiddleware::handle
#3 /core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\NegotiationMiddleware::handle
#2 /app/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Stack\StackedHttpKernel::handle
#1 /core/lib/Drupal/Core/DrupalKernel.php(717): Drupal\Core\DrupalKernel::handle
#0 /index.php(19): null

I fixed the issue by changing the settings of the Highlight:
Highlight returned field data -> If the server returns fields