Query negation throws error in SearchApiSubscriber.php

Created on 10 January 2024, over 1 year ago

Problem/Motivation

Error thrown with a query negation.

Warning: Array to string conversion in Drupal\google_tag\EventSubscriber\SearchApiSubscriber->onSearch() (line 61 of modules/contrib/google_tag/src/EventSubscriber/SearchApiSubscriber.php).
Drupal\google_tag\EventSubscriber\SearchApiSubscriber->onSearch(Object, 'search_api.processing_results', Object)
call_user_func(Array, Object, 'search_api.processing_results', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'search_api.processing_results') (Line: 624)

Query with normal value is handled as a string:

 array:2 [▼
  "#conjunction" => "AND"
  0 => "salt"
]

Negation query flows through as an array

 array:2 [▼
  "#conjunction" => "AND"
  0 => array:3 [▼
    "#negation" => true
    "#conjunction" => "AND"
    0 => "salt"
  ]
]

Steps to reproduce

1. Install Search API and create server and index
2. Install and configure GTM
3. Run a negation query: example ?query=-salt

Proposed resolution

Handle negation queries

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇺🇸United States jimconte

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

Comments & Activities

  • Issue created by @jimconte
  • 🇺🇸United States emptyvoid

    Getting warnings on every search on every index with Search API.

    Warning: Array to string conversion in Drupal\google_tag\EventSubscriber\SearchApiSubscriber->onSearch() (line 67 of /var/www/html/docroot/modules/contrib/google_tag/src/EventSubscriber/SearchApiSubscriber.php)
    #0 /var/www/html/docroot/core/includes/bootstrap.inc(108): _drupal_error_handler_real()
    #1 [internal function]: _drupal_error_handler()
    #2 [internal function]: strval()
    #3 /var/www/html/docroot/modules/contrib/google_tag/src/EventSubscriber/SearchApiSubscriber.php(67): array_map()
    #4 /var/www/html/vendor/symfony/event-dispatcher/EventDispatcher.php(246): Drupal\google_tag\EventSubscriber\SearchApiSubscriber->onSearch()
    #5 /var/www/html/vendor/symfony/event-dispatcher/EventDispatcher.php(206): Symfony\Component\EventDispatcher\EventDispatcher::Symfony\Component\EventDispatcher\{closure}()
    #6 /var/www/html/vendor/symfony/event-dispatcher/EventDispatcher.php(56): Symfony\Component\EventDispatcher\EventDispatcher->callListeners()
    #7 /var/www/html/docroot/modules/contrib/search_api/src/Query/Query.php(625): Symfony\Component\EventDispatcher\EventDispatcher->dispatch()
    #8 /var/www/html/docroot/modules/contrib/search_api/src/Query/Query.php(552): Drupal\search_api\Query\Query->postExecute()
    #9 /var/www/html/docroot/modules/contrib/search_api/src/Plugin/views/query/SearchApiQuery.php(621): Drupal\search_api\Query\Query->execute()
    #10 /var/www/html/docroot/core/modules/views/src/ViewExecutable.php(1486): Drupal\search_api\Plugin\views\query\SearchApiQuery->execute()
    #11 /var/www/html/docroot/core/modules/views/src/ViewExecutable.php(1514): Drupal\views\ViewExecutable->execute()
    #12 /var/www/html/docroot/core/modules/views/src/Plugin/views/display/Page.php(201): Drupal\views\ViewExecutable->render()
    #13 /var/www/html/docroot/core/modules/views/src/ViewExecutable.php(1690): Drupal\views\Plugin\views\display\Page->execute()
    #14 /var/www/html/docroot/core/modules/views/src/Element/View.php(81): Drupal\views\ViewExecutable->executeDisplay()
    #15 [internal function]: Drupal\views\Element\View::preRenderViewElement()
    #16 /var/www/html/docroot/core/lib/Drupal/Core/Security/DoTrustedCallbackTrait.php(107): call_user_func_array()
    #17 /var/www/html/docroot/core/lib/Drupal/Core/Render/Renderer.php(825): Drupal\Core\Render\Renderer->doTrustedCallback()
    #18 /var/www/html/docroot/core/lib/Drupal/Core/Render/Renderer.php(387): Drupal\Core\Render\Renderer->doCallback()
    #19 /var/www/html/docroot/core/lib/Drupal/Core/Render/Renderer.php(203): Drupal\Core\Render\Renderer->doRender()
    #20 /var/www/html/docroot/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(238): Drupal\Core\Render\Renderer->render()
    #21 /var/www/html/docroot/core/lib/Drupal/Core/Render/Renderer.php(593): Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}()
    #22 /var/www/html/docroot/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(231): Drupal\Core\Render\Renderer->executeInRenderContext()
    #23 /var/www/html/docroot/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(128): Drupal\Core\Render\MainContent\HtmlRenderer->prepare()
    #24 /var/www/html/docroot/core/lib/Drupal/Core/EventSubscriber/MainContentViewSubscriber.php(90): Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse()
    #25 /var/www/html/vendor/symfony/event-dispatcher/EventDispatcher.php(246): Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray()
    #26 /var/www/html/vendor/symfony/event-dispatcher/EventDispatcher.php(206): Symfony\Component\EventDispatcher\EventDispatcher::Symfony\Component\EventDispatcher\{closure}()
    #27 /var/www/html/vendor/symfony/event-dispatcher/EventDispatcher.php(56): Symfony\Component\EventDispatcher\EventDispatcher->callListeners()
    #28 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(188): Symfony\Component\EventDispatcher\EventDispatcher->dispatch()
    #29 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
    #30 /var/www/html/docroot/core/lib/Drupal/Core/StackMiddleware/Session.php(53): Symfony\Component\HttpKernel\HttpKernel->handle()
    #31 /var/www/html/docroot/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
    #32 /var/www/html/docroot/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
    #33 /var/www/html/docroot/core/modules/big_pipe/src/StackMiddleware/ContentLength.php(32): Drupal\Core\StackMiddleware\ContentLength->handle()
    #34 /var/www/html/docroot/core/modules/page_cache/src/StackMiddleware/PageCache.php(201): Drupal\big_pipe\StackMiddleware\ContentLength->handle()
    #35 /var/www/html/docroot/core/modules/page_cache/src/StackMiddleware/PageCache.php(138): Drupal\page_cache\StackMiddleware\PageCache->fetch()
    #36 /var/www/html/docroot/core/modules/page_cache/src/StackMiddleware/PageCache.php(87): Drupal\page_cache\StackMiddleware\PageCache->lookup()
    #37 /var/www/html/docroot/modules/contrib/advban/src/AdvbanMiddleware.php(57): Drupal\page_cache\StackMiddleware\PageCache->handle()
    #38 /var/www/html/docroot/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\advban\AdvbanMiddleware->handle()
    #39 /var/www/html/docroot/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
    #40 /var/www/html/docroot/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
    #41 /var/www/html/docroot/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle()
    #42 /var/www/html/docroot/core/lib/Drupal/Core/DrupalKernel.php(709): Drupal\Core\StackMiddleware\StackedHttpKernel->handle()
    #43 /var/www/html/docroot/index.php(19): Drupal\Core\DrupalKernel->handle()
    #44 {main}
    

    While the search results do render, every request is generating warning entries in the dblog.

Production build 0.71.5 2024