Starting this as a support request, but it might evolve into a bug report or feature request.
I'm trying to build a calender page, using Search API, solr backend and Facets. Each of the activities in my calendar can have one or more dates specified. I'd like to have a facet that groups activities into "today", "tomorrow", "this weekend", "this week", "next week", etc...
To achieve this, I have overridden the SearchApiDate class, more specifically the build() method. This way I can make sure that one activity is counted towards multiple facet entries (for example, on friday, an activity occurring on saturday will be counted both towards "tomorrow" and "this weekend").
However, one problem I cannot solve is when an activity has more than one date within a given range. For example, if one activity is occuring on both saturday and sunday, my "this weekend" facet will have an incorrect count of "2" instead of the expected "1". The problem seems to be that Search API feeds Facets a bunch of filters with counts, but no way to determine if multiple filters (=dates in my case) belong to the same entity, so I have no way to determine whether the "saturday" and "sunday" dates belong to one activity and should be listed as "weekend (1)", or as "weekend (2)".
Comments
Comment #2
borisson_So, I think that's by design. Search api supports showing data that is indexed in solr without it coming from drupal. That means we don't always have an entity id.
The only usecase I see is doing something like entityManger->getStorage('node')->loadByProperties('date' => $result); and doing the grouping like that.
I'm going to ping some people on irc for extra input.
Comment #3
drunken monkeyThat's not really solvable the way date facets are currently implemented, I'm afraid – i.e., returning all individual timestamp values that occur in the result set and then aggregating. That will just return multiple timestamps for a single item, if it has multiple ones, with no (useful) way to match them to that single item again.
Since returning individual timestamps and then aggregating them is a stupid way to do this anyways, with multiple other drawbacks, the solution here would be to change date facetting to instead use the complete ranges as the base for the facets and already return the result counts for those ranges. The main problems here are that a) the server backend plugin would have to support this, and currently none of them do, and b) that you might need to know the ranges you want beforehand (or it gets tricky to figure out). The latter doesn't apply in your use case, though, so that's already something. In that case, to solve it for your site, you'd just need to override the Solr backend (or just alter the query) to use proper range facets for the date facets – and then maybe override the facet plugin to deal with those results properly, too.
A general solution contributed back to the backend plugin(s) and this module would of course be even better. I think ekes was working on something like that? Maybe this: #2863611: Support range facets?
Comment #4
yoran scholiers commentedI recently ran into this issue as well. In my case I want to display events per month. However some events span multiple months (example: March 31 - April 1). The "March" facet will then show 1 event while april will have 0.
I'll look into the proposed solution in #3.
Comment #5
andrezstar commentedI was lookin for a similar solution than #1, but then i realised that even the year grouped facet does not work.
It shows something like
50068(2)
50073(1)
50074(1)
50076(3)
50077(1)
Comment #6
borisson_This is not possible to resolve with our current implemenation, closing the issue.
Comment #7
kmbremnerJust for the next person to stumble across this - I saw the same issue as #5.
It was an issue with elasticsearch_connector module that was resolved with the patch on https://www.drupal.org/project/elasticsearch_connector/issues/3096887