Adding author name to the Drupal search index

Awhile back, I wanted to add author names to the Drupal search index. After poking around a bit, I found that this was actually pretty easy. I created a new module called custom_helper and in it put the following function:

  1. <?php
  2. //Adding author name to the search index
  3. function custom_helper_nodeapi($node, $op, $arg = 0) {
  4. switch ($op) {
  5. case 'update index':
  6. if ($node->uid) {
  7. $user = user_load(array('uid' => $node->uid));
  8. return $user->name;
  9. }
  10. }
  11. ?>

One thing to keep in mind is that if you do this, then you will need to re-index all of your previously indexed nodes if you wanted them to be indexed by author name.

Custom_Helper...

Hello Julia,

Stumbled upon your site in a Google Search.
We want Drupal to include author names in it's search index.

Your code you posted is super helpful.
Just need you to fill in some gaps for me.

Do we need to create a fully functional module, with all the correct files, then upload and "turn on" or can we just upload a single module file with the code above?

We've never created a module before so any direction would be appreciated.
Nice site! Great info!

-Danny

Re: Custom_helper

Hi Danny,

Yep, you'll need to create a new module. It's really easy. Just create a .info file and then a .module file with the code I have. There are some great docs on creating Drupal modules available. Here's a nice resources:
http://drupal.org/node/231276

Feel free to contact me via the contact form if you run into problems.

Cheers,
Julia

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

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: <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.

More information about formatting options