You are here

function term_search_search_status in Term Search 7

Implements hook_search_status().

File

./term_search.module, line 163
Functions to index and search taxonomy terms.

Code

function term_search_search_status() {
  $remaining = $total = 0;

  // Get the indexed vocabularies.
  $vocabularies = variable_get('term_search_indexed_vocabularies', _term_search_default_vids());
  $vids = array_values(array_filter($vocabularies));
  if (!empty($vids)) {

    // Get the number of terms in all of the selected vocabularies.
    $total = db_select('taxonomy_term_data', 't')
      ->fields('t', array(
      'tid',
    ))
      ->condition('t.vid', $vids, 'IN')
      ->countQuery()
      ->execute()
      ->fetchField();
    $query = db_select('taxonomy_term_data', 't');
    $query
      ->leftJoin('search_dataset', 'd', 'd.sid=t.tid AND d.type=\'term\'');

    // Get the number of terms left to be indexed.
    $remaining = $query
      ->fields('t', array(
      'tid',
    ))
      ->condition('t.vid', $vocabularies, 'IN')
      ->condition(db_or()
      ->condition('d.sid', NULL)
      ->condition('d.reindex', '0', '<>'))
      ->countQuery()
      ->execute()
      ->fetchField();
  }
  return array(
    'remaining' => $remaining,
    'total' => $total,
  );
}