I had several issues trying to make date_facets work. I added some custom ranges in the future, e.g.
- this week: from "today" to "+ 7 days"
- this month: from "today" to "+ 1 month"
- this year: from "today" to "+ 1 year"
But the first issue was that the labels for my custom ranges were not shown in the facet block. I used the patch from https://drupal.org/node/2128521 which resolved that issue.
Then the second issue was that in Drupal_SearchApi_Facetapi_QueryType_DateRangeQueryType::getFacetItems() a HARDCODED config array is defined. So because my $key (this_week) was not in the array, the filter didn't do nothing at all.
Finally when the filter did return the correct results, I noticed that the count numbers in the facet block weren't correct. This is because the Drupal_SearchApi_Facetapi_QueryType_DateRangeQueryType::generateRanges() function is using a $diff to determine whether a result is in the specific range. Of course when you have an end in the future the diff will always be negative and therefore smaller than the range's diff. I.o.w. every result was being counted for every range!
My module versions:
- Date facets: 7.x-1.0-beta2+6-dev
- Search API: 7.x-1.9
- Facet API: 7.x-1.3
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | date_facets-future_ranges-2131831-2.patch | 9.37 KB | Sneakyvv |
Comments
Comment #1
Sneakyvv commentedComment #2
Sneakyvv commentedThe attached patch is built upon the patch from https://drupal.org/node/2128521, to solve the label issue, but refactors it into a separate function. Additionally the count and filtering is fixed with this patch as well.
Comment #3
Yaron Tal commentedLooks good and works good. Only problem is _date_facets_api_facet_create_label() only sending the fieldname to date_facets_get_ranges(). If it would also send the index_id ($options['index_id']) you could use that to get the $searcher. I didn't figure out how to get the full searcher string (including the module).
Maybe you could use facetapi_get_searcher_info() and then use the instance name to search on and the name to send to facetapi_adapter_load()? That way multiple searches on different indexes on one page would also work.
Comment #4
eugene.ilyin commentedHello.
Sorry for delay.
@Sneakyvv, thank you for your work, it's nice feature. But your patch was wrong, because after I applyed it, intervals for the future worked fine, but intervals for the past is not supporting. I fixed this problem in your patch. Commited b806e7b
P.S. multiple searchers are supported now.
Comment #5
eugene.ilyin commented