In search-result.tpl.php or in preprocess_search_result function, I want to keep $snippet. It is a great view to display search results.

But Apache Solr results, or Search module results, are displayed with terms that matches the query. These terms are designed to be hidden to anonymous. They can't be displayed in the snippet.

ex: Marguerite Duras … histoire " avec DURAS. Celle de deux personnes qui se reconnaissent avant de se connaître. Une … "Qui est Marguerite Duras ?" Il avait découvert l'écrivain, il allait rencontrer la …

The term Marguerite Duras is an admin tag. By the way, it is nice that the score relevancy depends on it.

How is created the snippet, or search_excerpt ? I tried the Taxonomy Hide module, but it doesn't affect search results.

1 Answer 1


The search result is a node view and hence the hook_node_view_alter works for it.

So you would could create a custom module and write the following function

function custom_node_view_alter(&$build, $type)
    if (($build['#view_mode'] == 'search_result') && ($type = 'node'))

change the field_tags to the name of your taxonomy field in the content type.

$build['#view_mode'] this variable defines the view we are on. In this case we are on the search_result view. And the $type defines the module in this case it is the node.

Use the following for Drupal 6

function custom_nodeapi(&$node, $op, $a3, $a4) {

  switch ($op) {
     case 'search result':
          $node = node_load($node->nid);
        $node->build_mode = NODE_BUILD_SEARCH_RESULT;
        $node = node_build_content($node, FALSE, FALSE);
        $node->body = drupal_render($node->content);
  • Thanks you for you fast answer. I totally forgot to mention that I'm using Drupal 6 and it seems that hook_node_view_alter comes with the 7.x version.
    – elektrorl
    Commented Jan 21, 2013 at 12:04
  • in drupal 6 it is hook_nodeapi and the $op would be view Commented Jan 21, 2013 at 12:08
  • In fact there is an $op for search_result like in node view alter: source
    – elektrorl
    Commented Jan 21, 2013 at 12:30
  • In 6 when it comes to the "search result" the taxonomy is already added to the body. so if you are OK with hacking the code then in the node.module near line number 1307 you have the code that add the taxonomy to the snippet you can comment that out if you want. :-) Commented Jan 21, 2013 at 12:40
  • It does not affect search results ($op = search result OR $op = view). I'm thinking of using apachesolr_search_snippets but I can't find good information on it. On hook_nodeapi neither… Please could you give me a hint?
    – elektrorl
    Commented Jan 21, 2013 at 13:21

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.