See attached patch

SOLUTION

BEFORE:

 // Pull the correct display value from the range definitions.
  foreach ($values as $key => $value) {
    $map[$value] = $ranges[$value]['#markup'];
  }

AFTER:

  // Pull the correct display value from the range definitions.
  foreach ($values as $key => $value) {
  if (isset($ranges[$value]['#markup'])) {
      $map[$value] = $ranges[$value]['#markup'];
    }
  }

#2219547: Date facets

Comments

joseph.olstad’s picture

StatusFileSize
new560 bytes
joseph.olstad’s picture

Issue summary: View changes
alamp’s picture

@joseph.olstad thanks a lot!. It works fine with the following versions.

  • search_api_facetapi 7.x-1.11
  • date_facets 7.x-1.0-beta2+10-
  • search_api 7.x-1.11
eugene.ilyin’s picture

Status: Needs review » Needs work

Hello. Thank you for patch, but how I can reproduce this problem?

eugene.ilyin’s picture

Any news?

zeip’s picture

We also have the same problem, although I'm not yet sure why this happens. The problem is that $values is an array of unix timestamps, and the keys in $ranges are today, tomorrow etc. The patch does fix the notices, although I'm unsure if it's the correct way to solve it. We're using a bunch of Search API and Facet related modules:

  • search_api
  • search_api_ajax
  • search_api_et
  • search_api_override
  • search_api_solr
  • facetapi
  • facetapi_bonus
  • facetapi_pretty_paths
  • facetapi_select
  • sarnia
eugene.ilyin’s picture

Status: Needs work » Postponed (maintainer needs more info)
eugene.ilyin’s picture

I've tried again but I can't reproduce it.
Please provide step-by-step instruction, how can I reproduce this problem and exact version of date_facets module.

eugene.ilyin’s picture

Status: Postponed (maintainer needs more info) » Closed (won't fix)
johan den hollander’s picture

I know this one is has status Closed but I feel I have some valuable information.

I'm seeing a lot of errors being logged. This patch fixes that for me.

Error: Notice: Undefined index: 2017-01-01T00:00:00Z in _date_facets_api_facet_create_label() (regel 71 van /sites/all/modules/contrib/date_facets/date_facets.module).

Url:
https://www.nvao.net/actueel/reactie-nvao-op-advies-onderwijsraad-%C3%A2...

This is not an url that is normally created while a user is using the facets. When the above mentioned url is visited one can see that multiple dates are selected.
I checked the ip's in the logs and they are all from the MSN bot.
So applying this patch does not prevent this type of behavior, but at least it keeps the error logs clean.

sgdev’s picture

I can provide step-by-step instructions on how to reproduce this problem. However, I do not believe patch #1 is the right way to fix it.

We are using the following modules:

Date Facets 7.x-1.0+5-dev
Search API 7.x-1.26
Facet API 7.x-1.5+30-dev
Ajax Facets 7.x-3.7+17-dev

I have done a lot of debugging of this issue, and at least in our case, the problem is due to search_api_facetapi_search_api_query_alter in Search API never being run when processing an Ajax request to update the date facet.

I was able to trace this from _date_facets_api_facet_create_label. The problem is this line of code, which returns an empty $ranges:

$ranges = date_facets_get_ranges($options['field']['key'], $options['index id']);

The reason this is empty is due to date_facets_get_ranges, which returns an empty value for $searchers:

$searchers = facetapi_get_active_searchers();

Diving deeper into this, the facetapi_get_active_searchers() function in the Facet API module returns empty values:

function facetapi_get_active_searchers() {
  $searchers = &drupal_static('facetapi_active_searchers', array());
  return $searchers;
}

And the active searchers are added to the static variable with this code:

function facetapi_add_active_searcher($searcher) {
  $searchers = &drupal_static('facetapi_active_searchers', array());
  $searchers[$searcher] = $searcher;
}

To add active searchers, FacetapiAdapter::addActiveFilters() has to be called automatically by a searcher's adapter. The *only* place this is done in the code is in the search_api_facetapi_search_api_query_alter function:

function search_api_facetapi_search_api_query_alter($query) {
  $index = $query->getIndex();
  if ($index->server()->supportsFeature('search_api_facets')) {
    // This is the main point of communication between the facet system and the
    // search back-end - it makes the query respond to active facets.
    $searcher = 'search_api@' . $index->machine_name;
    $adapter = facetapi_adapter_load($searcher);
    if ($adapter) {
      $adapter->addActiveFilters($query);
    }
  }
}

I have verified that hook_search_api_query_alter() is not being called when processing an Ajax request. I have also verified that disabling the Ajax Facets module resolves the issue, the code in hook_search_api_query_alter() is run successfully, and there are no longer any watchdog errors.

Seems like this might need to be moved to Search API as an issue.

sgdev’s picture

Status: Needs review » Needs work
sgdev’s picture

One additional follow-up to this issue. Was investigating a problem with Ajax Facets where the date facet was disappearing when removing a selected option.

Found that the issue was due to Ajax Facets not accepting the following global facet settings, which should be valid:

Display for searches: "For all except the selected"
Search IDs: <None>

Once the configuration was changed to this, it worked:

Display for searches: "Only for the selected"
Search IDs: <selected items from scrollable select field>

Also noticed after making this change, the Date Facets watchdog error was gone. So it seems as though both this issue and #3046720 do not support leaving "Search IDs" blank and setting "For all except the selected" as the display option.

This should work, but it doesn't. Selecting specific Search IDs fixes the problems.