Problem/Motivation

Using a date field on a search api view using a group filter with the between operator does not filter and shows and error in drupal log.
It does not happend if use the same filter on a normal view, so the problem seems to be related with both modules, date and search api.
It worked on 8.7 version but we updated the core to 8.8 and started to fail.

Steps to reproduce

  • Install search api
  • Index a date field
  • Create a search api view
  • Add some group exposed filters with the operator between
  • Choose the option "An offset from the current time such as" in the filter
  • Fill min with "-1 year" and max with "+1" year, "-2 years" "-1 year" ...
  • Try to filter by those options

Documentation

Here is the error:

Warning: Illegal string offset 'max' en Drupal\views\Plugin\views\filter\Date->acceptExposedInput() (línea 160 de /var/www/html/web/core/modules/views/src/Plugin/views/filter/Date.php)
#0 /var/www/html/web/core/includes/bootstrap.inc(600): _drupal_error_handler_real(2, 'Illegal string ...', '/var/www/html/w...', 160, Array)
#1 /var/www/html/web/core/modules/views/src/Plugin/views/filter/Date.php(160): _drupal_error_handler(2, 'Illegal string ...', '/var/www/html/w...', 160, Array)
#2 /var/www/html/web/modules/contrib/search_api/src/Plugin/views/filter/SearchApiDate.php(81): Drupal\views\Plugin\views\filter\Date->acceptExposedInput(Array)
#3 /var/www/html/web/core/modules/views/src/Form/ViewsExposedForm.php(192): Drupal\search_api\Plugin\views\filter\SearchApiDate->acceptExposedInput(Array)
#4 [internal function]: Drupal\views\Form\ViewsExposedForm->submitForm(Array, Object(Drupal\Core\Form\FormState))
#5 /var/www/html/web/core/lib/Drupal/Core/Form/FormSubmitter.php(112): call_user_func_array(Array, Array)
#6 /var/www/html/web/core/lib/Drupal/Core/Form/FormSubmitter.php(52): Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object(Drupal\Core\Form\FormState))
#7 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(591): Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object(Drupal\Core\Form\FormState))
#8 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(320): Drupal\Core\Form\FormBuilder->processForm('views_exposed_f...', Array, Object(Drupal\Core\Form\FormState))
#9 /var/www/html/web/core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php(134): Drupal\Core\Form\FormBuilder->buildForm('\\Drupal\\views\\F...', Object(Drupal\Core\Form\FormState))
#10 /var/www/html/web/core/modules/views/src/ViewExecutable.php(1238): Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase->renderExposedForm()
#11 /var/www/html/web/core/modules/views/src/ViewExecutable.php(1391): Drupal\views\ViewExecutable->build(NULL)
#12 /var/www/html/web/core/modules/views/src/ViewExecutable.php(1454): Drupal\views\ViewExecutable->execute(NULL)
#13 /var/www/html/web/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php(2438): Drupal\views\ViewExecutable->render()
#14 /var/www/html/web/core/modules/views/src/ViewExecutable.php(1662): Drupal\views\Plugin\views\display\DisplayPluginBase->preview()
#15 /var/www/html/web/core/modules/views_ui/src/ViewUI.php(605): Drupal\views\ViewExecutable->preview('page', Array)
#16 /var/www/html/web/core/modules/views_ui/src/ViewPreviewForm.php(62): Drupal\views_ui\ViewUI->renderPreview('page', Array)
#17 /var/www/html/web/core/lib/Drupal/Core/Entity/EntityForm.php(149): Drupal\views_ui\ViewPreviewForm->form(Array, Object(Drupal\Core\Form\FormState))
#18 /var/www/html/web/core/modules/views_ui/src/ViewFormBase.php(41): Drupal\Core\Entity\EntityForm->buildForm(Array, Object(Drupal\Core\Form\FormState))
#19 [internal function]: Drupal\views_ui\ViewFormBase->buildForm(Array, Object(Drupal\Core\Form\FormState), 'page')
#20 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(520): call_user_func_array(Array, Array)
#21 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(370): Drupal\Core\Form\FormBuilder->retrieveForm('view_preview_fo...', Object(Drupal\Core\Form\FormState))
#22 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(627): Drupal\Core\Form\FormBuilder->rebuildForm('view_preview_fo...', Object(Drupal\Core\Form\FormState), Array)
#23 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(320): Drupal\Core\Form\FormBuilder->processForm('view_preview_fo...', Array, Object(Drupal\Core\Form\FormState))
#24 /var/www/html/web/core/lib/Drupal/Core/Controller/FormController.php(91): Drupal\Core\Form\FormBuilder->buildForm(Object(Drupal\views_ui\ViewPreviewForm), Object(Drupal\Core\Form\FormState))
#25 [internal function]: Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch))
#26 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#27 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(573): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#28 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#29 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
#30 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(151): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#31 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#32 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#33 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#34 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#35 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#36 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#37 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#38 /var/www/html/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#39 /var/www/html/web/core/lib/Drupal/Core/DrupalKernel.php(694): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#40 /var/www/html/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#41 {main}

Comments

Eduardo Morales created an issue. See original summary.

eduardo morales alberti’s picture

pavnish’s picture

Assigned: Unassigned » pavnish

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

pavnish’s picture

Assigned: pavnish » Unassigned

I am busy in another task if someone wants to work on then plz assign to yourself.I have some busy schedule so i am un-assign this issue

liquidcms’s picture

I can confirm:
- grouped filters do not work for search api
- doesn't matter if a date filter; other grouped fields also do not work
- grouped date works as expected for content view (not search api)

I am testing with core: 8.8.8. Will try 8.7 and 8.9 next.

liquidcms’s picture

also, issue is not dependent on operator

liquidcms’s picture

a lot more testing on this and here is what i see:
- i have tried this on 2 sites now: large and small: small is basically a basic D8 install with searchapi and no solr, large has many modules including searchapi and solr

on the large site:
- grouped views on date field with "is between" fails when using searchapi; but not when using std content view
- this fails on core 8.8 and 8.9; not able to test with 8.7
- other filters grouped filter operators like "is equal to" work with searchapi

on small site:
- with 8.8 and 8.9 this works with searchapi

so my guess is that this is not a core issue. sounds like maybe a searchapi issue; but odd that it works on 1 site but not the other.

I also do not see any warnings like posted above. I do see a bunch of notices for undefined indexes related to views, and date.

I'll try to debug.

liquidcms’s picture

the issue seems to be this code that is in SearchApiDate.php

    // Unfortunately, this is necessary due to a bug in our parent filter. See
    // #2704077.
    if (!empty($this->options['expose']['identifier'])) {
      $value = &$input[$this->options['expose']['identifier']];
      if (!is_array($value)) {
        $value = [
          'value' => $value,
        ];
      }
      $value += [
        'min' => '',
        'max' => '',
      ];
    }

It mentions this issue on core: #2704077: Exposed operator for Views date filters doesn't accept "(not) empty", which although it is "Needs Review" state and i dont see that it has been committed; it is in my code (8.9.9) and the patch part is also on my small site (currently at 8.8.8) but the code within the elseif is different.

anyway, if i remove that entire section; my date filter works as expected.

But, guessing breaks something else.

liquidcms’s picture

that all being said, my small site, which has always worked, does of course still have that code in SearchApiDate as both sites had the same version of SearchAPI installed.

liquidcms’s picture

Status: Active » Closed (duplicate)

ughh.. oops.. still commenting on the wrong issue. Eduardo x-posted this to SearchAPI module; where it likely belongs. I'll close this as duplicate of #3111383: Can not filter using field date and exposed filter group filters