You are here

auto_index.module in Auto Index 6

Same filename and directory in other branches
  1. 8 auto_index.module
  2. 7 auto_index.module

Auto-index: Automatically indexes node content on update.

Uses Drupal's search module to automatically index updated nodes as and when they are updated. This means that a user can update node content and that content is immediately searchable, by users of the site.

@author Steve Osguthorpe <steve@futurate.com>

File

auto_index.module
View source
<?php

/**
 * @file
 * Auto-index: Automatically indexes node content on update.
 * 
 * Uses Drupal's search module to automatically index updated nodes as and when they are updated.
 * This means that a user can update node content and that content is immediately searchable,
 * by users of the site.
 * 
 * @author Steve Osguthorpe <steve@futurate.com>
 */
function auto_index_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  switch ($op) {
    case "delete":

      // Update search totals to reflect deleted node content.
      search_update_totals();
      break;
    case "update":
    case "insert":
      _auto_index_index_node($node);
      break;
  }
}
function auto_index_comment($a1, $op) {
  switch ($op) {

    // Reindex the node when comments are added or changed
    case 'insert':
    case 'update':
    case 'delete':
    case 'publish':
    case 'unpublish':
      _auto_index_index_node($a1);
      break;
  }
}
function _auto_index_index_node(&$node) {

  // Static variable to keep track of any node ids already indexed.
  static $indexed_nodes = array();

  // Extract the node ID
  $node_id = is_array($node) ? $node['nid'] : $node->nid;

  // Check if the node ID has already been indexed.
  if (array_search($node_id, $indexed_nodes) === false) {

    // Ensure we force the cache to be updated so latest content is indexed.
    $node_obj = node_load($node_id, NULL, TRUE);

    // Do the indexing of this node only.
    _node_index_node($node_obj);

    // Update search totals.
    search_update_totals();

    // Append to array to ensure node only indexed once per action.
    $indexed_nodes[] = $node_id;
  }
}

Functions

Namesort descending Description
auto_index_comment
auto_index_nodeapi @file Auto-index: Automatically indexes node content on update.
_auto_index_index_node