Problem/Motivation

When you use the facetapi_pretty_paths module in combination with page_manager, you get a solr error every time you clear the cache.

Steps to reproduce:

I started with a clean Drupal installation and created a new content type with a term reference field.

I created a solr server and a node index. I added the term reference field to solr and created a facet block for it.

In facet display I added a pretty path alias and checked the Reuse term alias checkbox.

I created a new view content pane for this node index.

Then i created a new page using page manager and i placed the view on it and the facets.

When I activate a filter everything works fine, but when I clear the cache using crush and I immediately refresh the page with pretty paths it gives an Solr java.lang.NumberFormatException.

When I disable this module, everything works fine again.

After some couple of hours digging into the code I found out that when I comment this line of code on line 693 in facetapi.module I always get this error. :

function facetapi_get_facet_info() {
....
//cache_set($cid, $facet_info[$searcher], 'cache', CACHE_TEMPORARY);
}

When i Comment this line of code the facet info no longer comes from the cache.

Any ideas?

Edit: I changed the Solr server to a database server and it doesn't show the facet filters or the view.

Comments

jeroent’s picture

I think it has something to do with the hook_facetapi_facet_info_alter().

When I delete the facetapi_adapter_load and replace it with $facet_settings->settings['pretty_paths_taxonomy_pathauto'] = 1; I don't get the error.

function facetapi_pretty_paths_facetapi_facet_info_alter(array &$facet_info, array $searcher_info) {
   //Loading the adapter within hook_facetapi_facet_info_alter() is evil as it
   //already builds the facet settings and statically caches them, without
   //including our alterations. Thus we have to clear the static cache of
   //facetapi_get_enabled_facets() at the end.
  //$adapter = facetapi_adapter_load($searcher_info['name']);
  foreach ($facet_info as &$facet) {
    $taxonomy_coder = 'taxonomy';
    //$facet_settings = $adapter->getFacetSettingsGlobal($facet);
    $facet_settings->settings['pretty_paths_taxonomy_pathauto'] = 1;
    if (module_exists('pathauto') && !empty($facet_settings->settings['pretty_paths_taxonomy_pathauto'])) {
      $taxonomy_coder = 'taxonomy_pathauto';
    }
    // Check for Apache Solr Taxonomy Term fields.
    if (!empty($facet['map options']['module_name']) && $facet['map options']['module_name'] == 'Taxonomy') {
      $facet['facetapi pretty paths coder'] = $taxonomy_coder;
    }
    // Check for Search API Taxonomy Term fields.
    else if (!empty($facet['field type']) && $facet['field type'] == 'taxonomy_term') {
      $facet['facetapi pretty paths coder'] = $taxonomy_coder;
    }
  }

  drupal_static_reset('facetapi_get_enabled_facets');
}
jeroent’s picture

Title: search_api_solr, Facetapi_pretty_paths and page_manager gives a solr error on every cache clear » Facetapi_pretty_paths and page_manager gives a solr error on every cache clear
Issue summary: View changes
dasjo’s picture

could you provide a patch for others to try out? that would be very much appreciated.
https://drupal.org/node/707484

jaydub’s picture

Status: Active » Needs review
StatusFileSize
new2.45 KB

I ran into this problem or at least a variation on this. I also believe that issue #2327729: Flush cache that makes views empty and show machine_name-tid is caused by the same issue.

I think I have figured out what is happening and have a patch that addresses the issue.

What happens is that on a cache clear, the facet info that is defined by this and other modules is rebuilt. Facet API Pretty Paths adds to the defined facet data in its hook_facetapi_facet_info_alter() hook. In this hook the facetapi_adapter_load() function is called. When this function is called the relevant defined searchers are retrieved or in the case of post cache clear are rebuilt and stored in cache. When this rebuild happens the searcher class in question is instantiated. When the class is instantiated a couple methods are run which in the end results in the fetchParams() method of the FacetapiUrlProcessorPrettyPaths class in url_processor_pretty_paths.inc to be called. This will attempt to process the current URL in order to parse the pretty path facets. However since the logic to append the facet info in hook_facetapi_facet_info_alter() happens AFTER this method is run (again, via facetapi_adapter_load), the result is that the current URL is parsed before the defined facets will have been altered to add in custom handling for taxonomy facets.

This is why you get a Solr error as Solr is sent a taxonomy facet without the facet having been parsed to pull out the taxonomy term ID alone.

The attached patch replaces the facetapi_adapter_load() call which is only there to extract facet settings with a direct call to facetapi_get_searcher_settings(). This gets the necessary facet settings w/o the side effect of the instantiation of the searcher class.

The patch includes a long comment to explain all this so the module maintainer can feel free to remove or shorten as necessary.

In my own testing locally this has resolved the issue with the failed searches (using Search API in our case).

jeroent’s picture

@Jaydub,

Thank you for your patch! I tried it, and the error was gone when I clear the cache.

dabbor’s picture

Thanks jaydub, the patch works for me too. I can confirm the need for such a patch, I was already worried I would need to continue debugging the Facet API Pretty Paths and figure the solution myself. I appreciate your detailed explanation of the problem ;)

  • jaydub authored 5f05ebc on 7.x-1.x
    Issue #2233741 by jaydub: Facetapi_pretty_paths and page_manager gives a...
dasjo’s picture

Status: Needs review » Fixed

Thanks @jaydub!

Patch looks solid. I was able to reproduce the problem on a local site and verified that the patch solves the issue.

Committed

Status: Fixed » Closed (fixed)

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