function term_search_update_index in Term Search 7
Implements hook_update_index().
File
- ./
term_search.module, line 64 - Functions to index and search taxonomy terms.
Code
function term_search_update_index() {
$limit = (int) variable_get('search_cron_limit', 100);
$vocabularies = variable_get('term_search_indexed_vocabularies', _term_search_default_vids());
// Pull out selected vids and store separately for the query.
$vids = array_values(array_filter($vocabularies));
if (!empty($vids)) {
// Get terms waiting to be indexed.
$query = db_select('taxonomy_term_data', 't');
$query
->leftJoin('search_dataset', 'd', 'd.sid=t.tid AND d.type=\'term\'');
$result = $query
->fields('t', array(
'tid',
))
->condition('t.vid', $vids, 'IN')
->condition(db_or()
->condition('d.sid', NULL)
->condition('d.reindex', 0, '<>'))
->orderBy('d.reindex', 'ASC')
->orderBy('t.tid', 'ASC')
->range(0, $limit)
->execute()
->fetchAllAssoc('tid');
// Index each term.
foreach ($result as $record) {
if ($term = taxonomy_term_load($record->tid)) {
// Render the term.
$content = taxonomy_term_view($term, 'search_index');
$term->rendered = drupal_render($content);
$text = '<h1>' . $term->name . '</h1>' . $term->rendered;
// Allow additional modules to include data.
$extra = module_invoke_all('term_update_index', $term);
foreach ($extra as $t) {
$text .= $t;
}
// Update index.
search_index($term->tid, 'term', $text);
}
}
}
}