[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/project_issue/search_index/ -> project_issue_search_index.module (source)

   1  <?php
   2  // $Id $
   3  
   4  /**
   5   * @file
   6   * Index project_issue content using Drupal search index.
   7   */
   8  
   9  /**
  10   * Implementation of hook_search().
  11   */
  12  function project_issue_search_index_search($op = 'search', $keys = NULL) {
  13    switch ($op) {
  14      case 'name':
  15        // We don't want this to show up in menus.
  16        return NULL;
  17  
  18      case 'reset':
  19        db_query("UPDATE {search_dataset} SET reindex = %d WHERE type = 'project_issue'", time());
  20        return;
  21  
  22      case 'status':
  23        $total = db_result(db_query("SELECT COUNT(*) FROM {node} WHERE status = 1 AND type = 'project_issue'"));
  24        $remaining = db_result(db_query("SELECT COUNT(*) FROM {node} n LEFT JOIN {search_dataset} d ON d.type = 'node' AND d.sid = n.nid WHERE n.status = 1 AND n.type = 'project_issue' AND (d.sid IS NULL OR d.reindex <> 0)"));
  25        return array('remaining' => $remaining, 'total' => $total);
  26    }
  27  }
  28  
  29  /**
  30   * Implementation of hook_update_index().
  31   */
  32  function project_issue_search_index_update_index() {
  33    $limit = (int) variable_get('search_cron_limit', 100);
  34  
  35    $result = db_query_range("SELECT n.nid FROM {node} n LEFT JOIN {search_dataset} d ON d.type = 'node' AND d.sid = n.nid WHERE n.type = 'project_issue' AND (d.sid IS NULL OR d.reindex <> 0) ORDER BY d.reindex ASC, n.nid ASC", 0, $limit);
  36  
  37    while ($node = db_fetch_object($result)) {
  38      _project_issue_search_index_index_node($node);
  39    }
  40  }
  41  
  42  /**
  43   * Index a single node.
  44   *
  45   * @param $node
  46   *   The node to index.
  47   */
  48  function _project_issue_search_index_index_node($node) {
  49    $node = node_load($node->nid);
  50  
  51    // Build the node body.
  52    $node->build_mode = NODE_BUILD_SEARCH_INDEX;
  53    $node = node_build_content($node, FALSE, FALSE);
  54    $node->body = drupal_render($node->content);
  55  
  56    $text = '<h1>'. check_plain($node->title) .'</h1>'. $node->body;
  57  
  58    // Fetch extra data normally not visible
  59    $extra = node_invoke_nodeapi($node, 'update index');
  60    foreach ($extra as $t) {
  61      $text .= $t;
  62    }
  63  
  64    // Update index
  65    search_index($node->nid, 'node', $text);
  66  }
  67  


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7