Hello everyone.

Upgrading from search_api 1.18 to 1.19 breaks facet-filters with "date range". The problem also exists in search_api 1.20.

I have date fields (ISO format) indexed as date in my search_api index.
I use Acquia Solr as server. Problem also exists when I use "database" as server (search_api_db).

Bug
After upgrading to search_api 7.x-1.19 and 7.x-1.20, facet-filters return "empty facet behavior" when I use "date range" as widget and query type.
When I downgrade to search_api 1.18, "date range" works fine again.
Facet-filter widget "links" with query type "date" is not broken in search_api 7.19 and 7.20.

Temporary Solution
Downgrade from search_api 1.20 to 1.18 in order to get "date range" to work.

Can anyone else please confirm this bug?
Thank you. Cheers :)

Comments

eevensen created an issue. See original summary.

gromani14’s picture

Hi eevensen, i have the same issue.. what i can see is that the regular expresion used to parse date is not working, I've changed by the expression defined into SearchApi and works.. i'm not sure if this is a final solution.. but maybe can help.

diff --git a/public/sites/all/modules/contrib/search_api/contrib/search_api_facetapi/plugins/facetapi/query_type_date.inc b/public/sites/all/modules/contrib/search_api/contrib/search_api_facetapi/plugins/facetapi/query_type_date.inc
index 6741cd8..d225a36 100644
--- a/public/sites/all/modules/contrib/search_api/contrib/search_api_facetapi/plugins/facetapi/query_type_date.inc
+++ b/public/sites/all/modules/contrib/search_api/contrib/search_api_facetapi/plugins/facetapi/query_type_date.inc
@@ -76,7 +76,7 @@ class SearchApiFacetapiDate extends SearchApiFacetapiTerm implements FacetapiQue
    */
   protected function createRangeFilter($value) {
     // Ignore any filters passed directly from the server (range or missing).
-    if (!$value || $value == '!' || (!ctype_digit($value[0]) && preg_match('/^[\[(][^ ]+ [^ ]+[])]$/', $value))) {
+    if (!$value || $value == '!' || (!ctype_digit($value[0]) && preg_match(FACETAPI_REGEX_DATE_RANGE, $value))) {
       return $value ? $value : NULL;
     }
drunken monkey’s picture

Where is the "date range" widget defined?

PS: It seems you (like many others – it's really easy to misinterpret) are confused by the "Issue tags" field. As the guidelines state, they aren't meant for free text tags related to the issue, but only for specific categorization purposes, usually by module maintainers.
So, if you aren't sure your current usage is correct, please just leave the field empty.

berdir’s picture

Looks like we are seeing this as well. This is coming through facetapi/facetapi_pretty_paths with a url that looks ike this:

/kurse/Start/[2017-04-14%20TO%202017-04-16]

What still works is just specifying the date.
/kurse/Start/2017-04-14

That this breaks between 1.18 and 1.19 helps, looking into whether I can find the exact issue now.

berdir’s picture

Status: Active » Needs review
StatusFileSize
new835 bytes

#2709719: Custom date range filter in [start TO end] format does not work is related and was closed.

Not sure why in your example this was still working in 7.x-1.18, but I tracked this down to #2665586: Notice: A non well formed numeric value encountered in SearchApiFacetapiDate->createRangeFilter(). There, a regex was introduced for the filter value, and it is a) broken (missing escape of ]) and doesn't match on [date TO date].

This fixes this for me, but it might not be the complete/right fix, as I assume the splitting/logic below is also not working as it should, this is just working around it by returning early.

Obviously solr specific then but I can live with that.

drunken monkey’s picture

Status: Needs review » Fixed

Thanks a lot for looking into this, seems your analysis is spot-on! It's indeed just a bad regex, otherwise this seems to work fine. And it's only Solr-specific if you use Solr's date format (or another kind of date string) – if you use UNIX timestamps, this should also work fine with all other backends, as far as I can see.
So: committed.
Thanks again!

  • drunken monkey committed c8a39a5 on 7.x-1.x authored by Berdir
    Issue #2780341 by Berdir: Fixed passing of custom ranges to date facets.
    
berdir’s picture

Status: Needs review » Fixed

d.o doesn't want this to be fixed ;)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.