coder1.com

  • home
  • drupal articles
  • contact
Home

Drupal Search : Index All Fields of a CCK Node

Mike Milano — October 1, 2008 - 3:04am

The Drupal Search API is powerful and pretty intuitive, but finding details on how to do something as simple as enabling searching on fields other than title and body could be a little daunting.

It's actually quite a simple concept. Anything exposed to your node view will be indexed. You can easily accomplish this by editing your content type and setting the Display Fields setting to Plain Text.

But what if you have a node view which you don't want everything in $node->body? i.e. inside node-mynodetype.tpl.php, you separate out the author field from the body field.

So here's the scenario: You're creating a node template for a CCK type 'quote'. A quote contains text fields for title, author, and body. Well Drupal handles the title and body already so we just need to add a text field for author.

Your template looks something like this:

  1. Author: <?php print $node->field_author[0]['value']; ?>
  2. <hr />
  3. <p><?php print $node->body; ?></p>

The problem now is that Author will show up twice. The easy way to fix this is to just use the content member of the $node variable. CCK will automatically add the fields and you can access them like this:

$node->content['field_author']['#value'];
$node->content['body']['#value'];

So now just apply that format to your template and you can isolate the node fields while allowing all fields to be indexed by the Drupal search engine.

  1. Author: <?php print $node->content['field_author']['#value']; ?>
  2. <hr />
  3. <p><?php print $node->content['body']['#value']; ?></p>

If you're not using CCK, just make sure your node exposes the content in the view hook.

Alternatively, you can either utilize hook_update_index (or hook_nodeapi with $op='update index'), or you can manually update an items index with search_index.

  • CCK
  • Drupal
  • Nodes
  • Search

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <img> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <h3> <h4> <h5> <h6> <h7>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. The supported tag styles are: <foo>, [foo].

More information about formatting options

Poll

Have you used any NoSQL Databases?:

User login

  • Request new password

Navigation

  • Recent posts

  • home
  • drupal articles
  • contact