Worked on this for a while as one of the facets for Drupal Commons would need to have future date ranges mixed in with a single catch-all past date range.
This patch adds in a tabledrag form on the facet configuration page that allows users to add a new date range, with a machine name that the facet uses for the query, a label that is displayed, and a starting and ending date range. Any facet that uses the date_range query type and widget that does not have any date ranges customized will automatically use the existing date ranges that exist currently in the module.

This workflow works on both Core and Solr facets, and the logic has been built into each respective search variant's class.
This patch also adds in the functionality from #1878586: Add counts to date ranges by adding the count logic into the code as well.
An example usage of this is in the following screenshot, where the "Next year" facet under "Date" has been added through the UI provided in the patch.

The only concern I would have is the AJAX handler that handles adding a temp row to the tabledrag table for the "add new date range" currently rebuilds the entire form, since the form uses a theme handler to build the tabledrag table.
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | date_facets.Implement-the-ability-to-customize-the-date-ranges-via-the-UI.1958362-17.patch | 3.63 KB | eugene.ilyin |
| #14 | 1958362-14.patch | 31.29 KB | nick_vh |
| #6 | 1958362-6.patch | 31.52 KB | nick_vh |
| #4 | date_facets.customizable_date_ranges.4.patch | 29.85 KB | jpontani |
| #2 | date_facets.customizable_date_ranges.2.patch | 27.41 KB | jpontani |
Comments
Comment #1
jpontani commentedUpdated patch to have date range counts for core search date range facets.
An example of this using core search (and the Faceted Navigation for Search module to have facets for core search):

Comment #2
jpontani commentedRe-roll with a good amount of code cleanup.
Comment #3
nick_vhis $range_data[..] safe enough as identifier?
Same here, is label safe enough?
I don't like html in a t() function, but I guess there's nothing we can do about it?
woa, very dense piece of code. Please add some commenting.
Also if you do a foreach, make sure the value exist and that it is iteratable. (is_array )
There must be a reason, but why ! if % gives you these tags>
whitespace issue
please add some more commenting to explain what you are doing here
you might want to use SolrBaseQuery::validFilterValue to check if your generated timestring is a valid solr string
same here, some more explanation would be useful
doxygen
again, very dense. Make it a little more enjoyable to read and understand please ;-)
Comment #4
jpontani commentedI would say yes in this case, as the machine_name is run through Drupal's built in machine_name Form API validation, which only allows alphanumeric characters and underscores.
I actually missed over that, and it is now being run through check_plain()
As for the rest, I went through and commented and made some slight changes as you suggested.
Comment #5
cpliakas commentedThe Search API integration work is complete, so bumping this up in priority since it is the next thing we should try to tackle.
Comment #6
nick_vhUpdated patch for the date facets, needs a facetapi change to be a little more clear for the users. Will post as soon as I have posted that patch
You'll need this patch : http://drupal.org/node/1984490#comment-7365696
Comment #7
cpliakas commentedMarking as posponed pending #1984490: Add support for OR logic in requirements.
Comment #8
cpliakas commentedDependent issue is in Facet API is resolved, resuming work on this issue.
Comment #9
cpliakas commentedPatch in #6 doesn't apply.
Comment #10
jos_s commentedWhen I apply this patch (from #4), I can configure new date ranges, but when I try to view them in my browser I get the following error message in my server log files:
PHP Fatal error: Cannot redeclare Drupal_Apachesolr_Facetapi_QueryType_DateRangeQueryType::generateRange()
Looks like a namespace problem. The protection function is declared twice in the patch.
Comment #11
jos_s commentedWould it also be possible to define fixed dates in the date ranges? I am working with historical data and would like to define date ranges from, say, year 1900 till now, years 1800 till 1899, years 1750 till 1799, etc.
I am not very good in php, but if someone could push me in the right direction I could try to implement this myself.
Comment #12
cpliakas commented#1859074: Can't select multiple date ranges is potentially related as we support OR facets for dates and introduce custom ranges.
Comment #13
muschpusch commented#6 doesn't apply and doesnt seems to be complete because it doesn't patch lib/Drupal/SearchApi/Facetapi/QueryType/DateRangeQueryType.php
Could you please re-roll the patch?
Comment #14
nick_vhUpdated version
Comment #15
nick_vhCommitted
Comment #16
eugene.ilyin commenteddate_facets/lib/Drupal/SearchApi/Facetapi/QueryType/DateRangeQueryType.php
this class also uses function date_facets_get_ranges, but now this function requires argument, and module will not works for SearchAPI
Need additional work.
Comment #17
eugene.ilyin commentedSeems I adapted it for searchApi. But maybe need some additional testing and work. Everybody can use this patch. It also was commited into 7.x-1.x-dev
Also I have question - why you did so? Why range for DAY applyed for all types (HOUR, DAY, WEEK...)
Comment #18
bennos commentedinstalled the dev version which includes above patch.
mayby my bug issue is related to this.
see
https://drupal.org/node/2065113
Comment #19
muschpusch commentedthe patch doesn't apply to current dev or latest beta. The module is kind of broken at the moment...
Comment #20
nick_vhThis patch was committed. If you want to make a follow up, please create a new issue - it becomes too confusing other wise.
It works well with apachesolr and would want to fix it for search api but I need some help in getting there.