Score:1

Adding a relative date range facet to a Search API view using the "last updated" field

cn flag

I would like to add a facet to a search_api view filtering on the content "changed" field. I would like to use friendly naming like "This week", "This month" etc. There is an answer here stating that custom code is needed. However this answer is for Drupal 6 (about 8 years old) and refers to a date range field while "changed" is a timestamp.

Currently if I add Date processor capability to this facet I have a granularity option. If I select a month granularity I get a basic "time ago" feature but seem to get very odd results.

EG. Clicking on "3 months ago (3)" in the below list gives me 13 items. The url generated is &facets_query=&keyword[0]=last_updated:2021-05-22 (As of today July 22)

Last updated
3 months ago (3)
6 months ago (3)
7 months ago (2)
8 months ago (9)
10 months ago (1)
11 months ago (6)
1 year 0 months ago (7)

Questions:

  1. Is there an updated answer available for creating a friendly set of date ranges?
  2. Why could I be I getting these incorrect facet counts?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.