3

Using the Token module with the Token Filter module, one can put a token in the body of a node.

When visitors search for a content they would like to find whatever is show in page, no matter how is it placed there. However, tokens are only replaced before node renders. Is it possible that the search mechanism could index the token content?

2

The search index includes the content of the nodes after they are rendered.

node_update_index() is an implementation of hook_update_index(), the hook that is invoked when the search index needs to be updated; it calls _node_index_node() which contains the following code.

  $node = node_load($node->nid);

  // ...

  // Render the node.
  $build = node_view($node, 'search_index');
  unset($build['#theme']);
  $node->rendered = drupal_render($build);

  $text = '<h1>' . check_plain($node->title) . '</h1>' . $node->rendered;

  // ...

  // Update index
  search_index($node->nid, 'node', $text);

Similar code is present in _node_index_node() for Drupal 6.

  $node = node_load($node->nid);

  // ...

  // Build the node body.
  $node->build_mode = NODE_BUILD_SEARCH_INDEX;
  $node = node_build_content($node, FALSE, FALSE);
  $node->body = drupal_render($node->content);

  $text = '<h1>' . check_plain($node->title) . '</h1>' . $node->body;

  // ...

  // Update index
  search_index($node->nid, 'node', $text);

In your case, if the node body contains a token such as [global:test], whose content is test, the search index will contain test, not [global:test].

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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