Where is $search_results generated?

I've got an Apache Solr search, and I want to reorganize the content in a certain way, and modifying the theming as well based on certain conditions, but all I have with $search_results is a string with a list.

What I want is to segregate search results based on a value in the object that Apache Solr creates.

3 Answers 3


About theming results, you should have 2 templates: search-results.tpl.php and search-result.tpl.php (without s).

The first one allows you to theme the list, the second one (without the s) allows you to theme the results individually.

So I would advise you to use a hook to sort/filter the results the way you want (see answers from Clive and arrubiu), but use the templates to define the design you want.


It's generated in template_preprocess_search_results():

foreach ($variables['results'] as $result) {
  $variables['search_results'] .= theme('search_result', array('result' => $result, 'module' => $variables['module']));
  • Where would I use template_preprocess_search_results? In my module? or in, say, template.php?
    – Jack Ryan
    Feb 5, 2014 at 18:47
  • Traditionally you'd implement hook_preprocess_search_results(), but that won't work here as the string is already built (sure you already know that). If you really want to alter what happens in that function you're looking at implementing hook_theme_registry_alter() to replace the preprocess/theme hooks with your own. But as Matt advised in another answer that sort of logic really doesn't belong in the theme layer if you can possibly avoid it
    – Clive
    Feb 5, 2014 at 19:07

You could, in custom module, use hook_apachesolr_process_results to manage results after they are returned from Solr.

But I don't know if this hook gives you what you need. Try it :)

  • Yes, that's the hook we're using so far, but for some reason the results are not ordered correctly on output even though they are in a printing out of the variable.
    – Jack Ryan
    Feb 5, 2014 at 18:11

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.