Add an option to exclude future items

Created on 4 May 2023, over 1 year ago
Updated 12 May 2023, over 1 year ago

Problem/Motivation

If an entity uses the "created" timestamp but this value (deliberately or accidentally) is set into the future, NewResultsCheck::getNewResults() will always consider the entity to be new, and will repeatedly notify about it until the date has passed.

Steps to reproduce

Add a saved search for nodes.
Create a node that matches the search with the "authored on" timestamp in the future.

Proposed resolution

This query only checks that the date field is after the last time we executed a search:

      $query->addCondition($date_field, $search->get('last_executed')->value, '>');

Add another condition to ensure the date field is in the past:

      $query->addCondition($date_field, $search->get('last_executed')->value, '>');
      $query->addCondition($date_field, $this->time->getRequestTime(), '<=');
Feature request
Status

Active

Version

1.0

Component

Code

Created by

🇬🇧United Kingdom longwave UK

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

Comments & Activities

  • Issue created by @longwave
  • Status changed to Closed: works as designed over 1 year ago
  • 🇦🇹Austria drunken monkey Vienna, Austria

    Thanks for reporting this problem!
    However, this seems to be a very specific problem, and more or less expected behavior. It’s your own responsibility to not set a date field that might be in the future as the “Method for determining new results” option.
    On your own site, you can also fix this by just altering the executed search query – though, admittedly, not through the usual search_api.query_pre_execute event, but only through a backend-dependent one.

  • Status changed to Active over 1 year ago
  • 🇬🇧United Kingdom stewsnooze

    I'm not sure I agree with that. Even the function name is called getNewResults() but will actually always provide all future results. Thus meaning that this module will not alert you once to a new result which it claims to do.

    Later on in the module on line 294 there is code to force a return of the result set which I think may be the reason we always get the returned set rather than only new results that haven't been saved into saveKnownResults()

        // Same when we used a date field, but in this case with results.
        if ($date_field) {
          return $results;
        }
    

    If you are not against it I still think there is a completely valid case where some work could be done here to ensure the result set should not constantly have future dates items. We are happy to do the work but I do think this is a valid use case to strengthen the module.

  • 🇦🇹Austria drunken monkey Vienna, Austria

    OK, you’re still not convincing me this is a bug, but I guess it would be OK as a feature request, if we make it optional. (I.e., with a setting on the saved search type form.) If you’re prepared to provide a patch/MR for that, including tests, then I’d be willing to review and merge it.

Production build 0.71.5 2024