I've posted this at d.o, but I'm hoping maybe someone here might be able to help. (The documentation on apachesolr for D7 is so far rather depressing.)

I wrote a module for a D6 site implementing hook_apachesolr_process_results to modify the snippets of text shown on the search results page. That worked like a charm. We've now moved on the D7. I've again written a module to implement the same hook. This is a lowest-comment-denominator version of the function:

function mysearch_apachesolr_process_results(&$results, $query){
  foreach($results as $id => $result){
    $results[$id]['snippet'] = "FOOBAR";

The call at the end debug_to_file is a utility function I use to print_r a variable to a file. That call proves that a) my code IS indeed getting run and b) that the $results variable has been changed internally. However, my search results page has nary a FOOBAR to be found!

Could it possibly be an interaction between apachesolr and another module? Apachesolr and my theme (fusion 7.x-1.x-dev)?

It'd even be helpful here to get an indication of what to try next as far as debugging. Any advice would be useful!

FTR, I'm using Drupal 7 with the ApacheSolr Search and Framework modules at version 7.x-1.0-beta12.

2 Answers 2


Grr. Someone outside of StackExchange suggested a few routes of debugging that would weed out issues having to do with interaction of my code with other code. One of those suggestions was to go back to a default theme and see if my change showed there. It did. I talked to my themer to see if he had any insight.

And, that's when we hit the "a-ha" moment: We were using a custom theme based off of Fusion. (Incidentally, when I switched to stock Fusion, everything worked correctly.) At that point, it was just a matter of flipping through all of the "Appearance" settings to find that under search results none of the checkboxes were ticked. Guess what happened when I ticked the "snippet" checkbox?? Yeah....

Though, we did learn something good here, at least: If you create a new theme as a custom sub-theme of an existing theme, your subtheme does not inherit the settings of its parent theme.


Maybe you want to implement hook_preprocess_search_results(). As for the individual search results themselves, you will be able to use hook_preprocess_search_result(). You use the former when you want to modify the block that contains the search results. The later is used when you want to modify each individual result. I rely on them both for my Solr theming in D7.

  • What's the benefit to implementing those hooks (are they in the search API?) over implementing the apachesolr-specific hooks?
    – Jonathan
    Commented Dec 20, 2011 at 11:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.