You are here

function data_search_search in Data 6

Same name and namespace in other branches
  1. 8 data_search/data_search.module \data_search_search()
  2. 7 data_search/data_search.module \data_search_search()

Implementation of hook_search().

File

data_search/data_search.module, line 105

Code

function data_search_search($op = 'search', $keys = NULL) {
  switch ($op) {
    case 'name':
      return t('Data');
    case 'reset':
      $tables = data_search_get_tables();
      foreach ($tables as $table) {
        $name = $table
          ->get('name');
        db_query("UPDATE {search_dataset} SET reindex = %d WHERE type = '%s'", time(), $name);
      }
      return;
    case 'status':
      $total = $remaining = 0;
      $tables = data_search_get_tables();
      foreach ($tables as $table) {
        $name = db_escape_table($table
          ->get('name'));
        $schema = $table
          ->get('table_schema');
        $base_field = current($schema['primary key']);
        $total = $total + db_result(db_query("SELECT COUNT(*) FROM {{$name}}"));
        $remaining = $remaining + db_result(db_query("SELECT COUNT(*) FROM {{$name}} dt LEFT JOIN {search_dataset} d ON d.type = '{$name}' AND d.sid = dt.{$base_field} WHERE (d.sid IS NULL OR d.reindex <> 0)"));
      }
      return array(
        'remaining' => $remaining,
        'total' => $total,
      );
  }
}