Problem/Motivation

There are 2 ways i can see to add a date range end value:

1. add the full Date field and in view select end value as click sort and rewrite field as just the end value.
2. add only the end date to the index and add this in the view

1. does show the end date correctly; but regardless of what is selected for sort; it only uses the start date for sorting

2. causes the view to crash with the error:
InvalidArgumentException: The timestamp must be numeric. in Drupal\Component\Datetime\DateTimePlus::createFromTimestamp() (line 198 of E:\www\drupal8\web\core\lib\Drupal\Component\Datetime\DateTimePlus.php).

Steps to reproduce

- default D8 site
- add a date range field to Article bundle
- add end value of this field to search index
- create a view listing indexed end date

running the view gives wsod.

Proposed resolution

As i think SearchAPI/Views cannot sort on rewritten values; i think the correct solution would be to have the End Value field work correctly as a separate indexable value.

Remaining tasks

Comments

liquidcms created an issue. See original summary.

drunken monkey’s picture

Title: Can't sort on Date Range end value. » Can't display date Range end value in Views
Component: General code » Views integration
Status: Active » Needs review
StatusFileSize
new4.12 KB
new5.97 KB

Thanks a lot for reporting this problem.
As you yourself state, though, the real problem here is that displaying end dates in Views leads to a fatal error. Everything else seems to work fine. Adapting the title accordingly.

Anyways, I could easily reproduce the problem, after a bit also found a reasonably clean solution (not exactly perfect, but good enough, I think) and then even managed to write a regression test for the bug.
Please test/review the attached patch and see whether it resolves the problem for you, too.

liquidcms’s picture

Hey dm, thanks for the patch. I ended up doing a few computed fields in my entity to get around the problem that re-written fields can't be sorted. This would have been one of them. Seemed a little hacky; but did the job nicely.

I'll try to test your patch on a generic test site i think i still have set up.

Thanks again.

drunken monkey’s picture

Do you still plan on testing this? Would be great to get feedback.
Otherwise, I can either commit and hope for the best or risk losing both our efforts.

liquidcms’s picture

Status: Needs review » Needs work

Tested. View no longer crashes; but view is not sortable on the end date field.:
- https://take.ms/O8TRm
- https://take.ms/Ivhw0z

drunken monkey’s picture

Status: Needs work » Needs review

It works fine for me. Did you maybe forget to reindex after adding the field?
Otherwise, please tell me the generated search query (if you have Devel installed, adding dpm((string) $query); at the top of \Drupal\search_api\Entity\Server::search() should suffice) and what backend you are using. If the correct query is generated (and you did reindex), then the backend plugin seems at fault.

  • drunken monkey committed 4eb7b41 on 8.x-1.x
    Issue #3187134 by drunken monkey: Fixed display of date range end values...
drunken monkey’s picture

Status: Needs review » Fixed

Committed.

liquidcms’s picture

hey, sorry i didnt get a chance to restest. Unlikely i wouldn't have re-indexed. This was using solr on the real site but drupal db on a test site. Both presented the issue.

I think it is safe to assume if you have fixed issue #2 so that end date can now be indexed; there shouldnt be any reason it wouldn't be sortable in a View. :)

thanks.

Status: Fixed » Closed (fixed)

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