Recurring Dates in Search-based views orders by first instance

Created on 19 April 2021, over 3 years ago
Updated 5 December 2023, about 1 year ago

Problem/Motivation

Recurring dates in search-based views appear to order based on the first instance of the date value instead of the next instance of the date as one might expect.

Steps to reproduce

  • Set up the Smart Date starter kit module on a fresh install of Drupal. I go to the event field settings, and enable recurring date support.
  • Enable and Search API
  • Created a database-based search server and index.
  • Set up a view that uses the search index as it's base, and configure it to display the "Title" and "when" fields.
  • Then add the "When" field as the sort"
  • Add content as such: Create one event that has an initial date starting some time in the past. have it recur weekly (preferably on a day a few days after your current time). Create another event, optionally use singe, or recurring dates. Have that event start date occur in the future, but before the next instance of the first event.
  • Now go to your search view. You may see something along the lines of this output:

Events that starts April 1st recurs to June

Weekly on Thursday All day until Thu, Jun 24 2021
UPCOMING
Thu, Apr 22 2021, All day
Thu, Apr 29 2021, All day

Event that starts April 20

Tue, Apr 20 2021, 9 - 10pm

The recurring April 1st event's next instance is April 22, However, this appears before the April 20th event in the result.

Proposed resolution

I don't have a resolution. I'm not even sure if one is possible... I am guessing that under the hood, the query sorts results before it filters them out. I'm not sure if there is a way to reverse that.

I don't know how this would behave in Solr or ElasticSearch.

πŸ› Bug report
Status

Closed: works as designed

Version

3.2

Component

Smart Date Recur

Created by

πŸ‡ΊπŸ‡ΈUnited States bburg Washington D.C.

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States BDuell

    Any luck on this @BenStallings ?

    Thank you!

  • πŸ‡ΊπŸ‡ΈUnited States BenStallings

    @BDuell, honestly I don't remember what I wound up doing with that. :S
    It looks like maybe this scratched my itch: https://www.drupal.org/node/3300819 β†’

  • πŸ‡¨πŸ‡¦Canada plousia

    I'm having the same issue and wonder if this is getting any attention? It seems like a common use case and a pretty needed functionality.

    I have a site with "programs" with recurring dates. I have to be able to display only the next instance of the date, and sort the view on that. The patch in the issue linked in #11 does allow you to output the next instance in a view, but not to sort by it (unless I'm missing something).

  • πŸ‡¨πŸ‡¦Canada mandclu

    From everything I've read, Solr is unable to properly sort on a multivalued field. That is not a limitation of Smart Date, nor is it something this module will be able to fix. Unless someone has a better solution, I would suggest that the only solution is to not use Solr if you want to sort on multivalued (e.g. recurring) dates.

  • πŸ‡¨πŸ‡¦Canada plousia

    Maybe this isn't the issue I should have posted in; I'm just looking to sort in a regular view, not Solr. Is that possible?

  • πŸ‡¨πŸ‡¦Canada mandclu

    @plousia yes, the Smart Date Starter Kit includes a view that works this way out of the box. The upcoming events display should be pretty close to what you want, especially if you set it to use the recurring formatter.

  • πŸ‡¨πŸ‡¦Canada plousia

    Thanks. I can't install Smart Date Starter Kit because I already have a content type called "event". But looking at the YML for the view that comes with it, the sorts for the upcoming display are like this:

    sorts:
            field_when_value:
              id: field_when_value
              table: node__field_when
              field: field_when_value
              relationship: none
              group_type: min
              admin_label: ''
              plugin_id: '1'
              order: ASC
              expose:
                label: ''
                field_identifier: field_when_value
              exposed: false
              granularity: second

    This is the sorts YML for my view, which looks pretty identical, but it's still not sorting by next upcoming date:

    sorts:
            field_event_dates_value:
              id: field_event_dates_value
              table: node__field_event_dates
              field: field_event_dates_value
              relationship: none
              group_type: min
              admin_label: ''
              plugin_id: date
              order: ASC
              expose:
                label: ''
                field_identifier: ''
              exposed: false
              granularity: second

    Happy to provide any more information that might be needed to diagnose the issue.

  • πŸ‡¨πŸ‡¦Canada mandclu

    Do you have your view filtered to only show upcoming dates?

  • πŸ‡¨πŸ‡¦Canada plousia

    Yes.

  • πŸ‡¨πŸ‡¦Canada plousia

    Figured out what the issue was, in case this may help someone else. My view has aggregation turned on, and the aggregation setting for the "date field > now" filter was set to MIN. Changing it back to the default "group results together" fixed the problem and the events are now sorting according to upcoming date.

    I found another weird issue, though. If you set a Smart Date recurring field to "ends on" a specific date, rather "ends after" a certain number of instances, that content doesn't sort properly with content with the date field recurrence set to "ends after". That doesn't seem like the expected behaviour.

  • Status changed to Closed: works as designed about 1 year ago
  • πŸ‡¨πŸ‡¦Canada mandclu

    I've come to the conclusion that reported behaviour here is really a limitation of Solr and as such not something that Smart Date would be able to address. Feel free to reopen if someone identifies a way.

Production build 0.71.5 2024