On a recent project, I ran into an issue with the hash that gets generated off $searcher, $realm_name, $facet_name. We have a fairly typical dev, stage, prod setup. Each of our searchers are for different environment setups with different solr servers. This is working for us, until we use context to place blocks on our site.

Since the searcher changes by environment, the hash changes and a block that was displaying in dev no longer displays in stage. This adds a drupal_alter to the hash so we can alter it to have essentially the same hash in all environments. Example implementation provided.

function example_facetapi_hash_alter(&$hash, $delta) {
  preg_match('/(.+@)(.+?)(:.+)/', $delta, $matches);
  $delta = $matches[1] . EXAMPLE_SEARCHER_ID . $matches[3];
  $hash = substr(drupal_hash_base64($delta), 0, 32);
  $hash = strtr($hash, array('-' => '0', '_' => '1'));
}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

heddn’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, facetapi_hash_alter.patch, failed testing.

cpliakas’s picture

Version: 7.x-1.2 » 7.x-1.x-dev

Thanks, heddn!

I like the idea of this patch. Specifically, I think it will buy us some time with the bug posted at #1818796: CSS id and classes should be case sensitive matching $delta in addition to the use case you mentioned. Moving to the 7.x-1.x-dev branch so the test bot can hack at the latest code.

Out of curiosity, are you using Search API or Apache Solr Search Integration?

Thanks,
Chris

heddn’s picture

Status: Needs work » Needs review
FileSize
870 bytes
heddn’s picture

Sorry I missed your question about search api or solr. For the project in question we are using apachesolr.

mvc’s picture

Status: Needs review » Reviewed & tested by the community

worked perfectly to work around #1818796: CSS id and classes should be case sensitive matching $delta with facetapi 7.x-1.2. with this patch i was able to run the following hook:

function example_facetapi_hash_alter(&$hash, $delta) {
  $hash = drupal_html_class($hash);
}

fwiw i did have to manually update block.delta (i think that module was checking case-insensitively to see if deltas already existed).

thanks!

heddn’s picture

Can we get this committed? I ran into this same problem on another site. Several hours of troubleshooting later, I remembered I filed this issue. And it fixed the problem right away.

heddn’s picture

Issue summary: View changes

re-worked the example implementation

cpliakas’s picture

Title: facetapi_hash_alter » Add a hook to alter the block delta
Issue summary: View changes

  • cpliakas committed 6029413 on 7.x-1.x authored by heddn
    Issue #1828396 by heddn, mvc: Add a hook to alter the block delta.
    
cpliakas’s picture

Status: Reviewed & tested by the community » Fixed

  • cpliakas committed 6d5e0ae on 7.x-2.x authored by heddn
    Issue #1828396 by heddn, mvc: Add a hook to alter the block delta.
    

Status: Fixed » Closed (fixed)

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