if ($active = $this->adapter->getActiveItems($this->facet)) {
      $item = end($active);
      $field = $this->facet['field'];
      $regex = str_replace(array('^', '$'), '', FACETAPI_REGEX_DATE);
      $filter = preg_replace_callback($regex, array($this, 'replaceDateString'), $item['value']);
      $this->addFacetFilter($query, $field, $filter);
    }

I believe it all starts going bad at that end($active) part

CommentFileSizeAuthor
#1 2114451_search_api_facets_date_or-1.patch1.69 KBhefox

Comments

hefox’s picture

Status: Active » Needs review
StatusFileSize
new1.69 KB

http://gyazo.com/ab6beaf84d16de37d8c2ab97f502a3bb

This looks to work

Other than there's another bug that I shall be filling now (http://gyazo.com/7b34d5753a3bff7fdbe41fd73f262a8a)

drunken monkey’s picture

Status: Needs review » Needs work

Thanks for opening this issue and providing a patch!
I tested it, but I don't see any difference after applying the patch. Is your date field maybe multi-valued? That's a whole different can of worms, which can currently not be solved – see #2104623-3: Date facet: granularity option does not show up for multiple date fields.

Regarding the OR issue: Currently, the OR option isn't supported at all for date facets, we should probably have removed it altogether. (Unless we come up with a way to fix it here, we probably should.) And I think that larger changes would be necessary to support it. For one, we'd have to check the hierarchy more carefully, to see whether ranges lower down are actually part of the upper ranges, and then drill down separately for all selections. Several selections in the same hierarchy (e.g., both "2012" and "March 2012") should then of course not be ORed together, but only the most specific one used.

If you'd be able to come up with a patch that solves this, I'd gladly review and commit it! But, as said, the provided one doesn't seem to work for me.

(Note: I marked the other issue as a duplicate, I think they're both about the same problem.)

hefox’s picture

I re-opened that issue before reading this as these look like separate but related issues to me. The patch works for me; single value field, but using granualrity. Would both 2012 and March 2012 appear at the same time?

drunken monkey’s picture

Title: Or option for date options only works for one options » Fix date facets with OR operator

Ah, OK, I see now what the patch does, and yes, it really corrects how the filters are applied at least in some cases (two separate ranges). However, the hierarchy is still completely wrong, and as it's unusable in the current state (with #1 applied) I don't think we should split this into two issues, but solve these problems all at once. (Especially, just removing hierarchy altogether, as proposed in #2114465: OR-ed date facet with granulitiry has messed up hierarchy, is certainly no alternative.) I'd certainly not commit this one with the other being ready too, and therefore this only makes testing the patches harder.

Have you tried the facet out with AND, to see how the hierarchy should work? I think we should keep the same style for OR facets, just displaying separate trees for disjoint active facets. Furthermore, as explained above, we'd have to take care to only apply the most specific ranges (i.e., active facets with no active descendants) – with the above patch, selecting "May 2012" after "2012" will have no effect (as the range becomes "2012 OR May 2012").

To illustrate this with an example:
Initial facets:

  • 2011
  • 2012
  • 2013

Click on "2012" -> only results from 2012 are shown. New facets (active ones in bold):

  • 2011
  • 2012
    • May 2012
    • July 2012
  • 2013

Click on "2013" -> results from 2012 or 2013 are shown. New facets:

  • 2011
  • 2012
    • May 2012
    • July 2012
  • 2013
    • March 2013
    • October 2013

Click on "May 2012" -> results from May 2012 or from 2013 are shown. New facets:

  • 2011
  • 2012
    • May 2012
      • May 15 2012
      • May 21 2012
    • July 2012
  • 2013
    • March 2013
    • October 2013
drunken monkey’s picture

Issue summary: View changes

forgot ?

acrazyanimal’s picture

Issue summary: View changes

@drunken_monkey Curious to know if any work has been done on this or if you are awaiting a contributed patch?

drunken monkey’s picture

I'm currently just waiting whether someone wants to contribute a patch. I can't really say when I'd have the time to look into this more closely myself.
However, this should get quite a lot easier if #1888174-11: Offset between stored and indexed date gets committed, so anyone who wants to give this issue a try should probably base their patch on that one (and help me get it committed by verifying that everything still works fine with it).

BarisW’s picture

In cases where only a year is displayed, an OR filter would be very useful. For example; listing items in 2017 OR 2016.
The OR operator also enables the option to use the facets as navigational buttons, like here: http://vnconline.nl/actueel

With the AND operator set as default makes that when you select 2017, all other years are removed from the facet.

bohus ulrych’s picture

FYI Here I've found working solution for me #2290019 Year facet drills down to the remaining year values

ronino’s picture

Status: Needs work » Closed (duplicate)
Related issues: +#2290019: Year facet drills down to the remaining year values

This is indeed a duplicate of #2290019: Year facet drills down to the remaining year values which adds support for the OR operator and already has been committed to dev.