You are here

function synonyms_search_taxonomy_term_update in Synonyms 7

Implements hook_taxonomy_term_update().

File

synonyms_search/synonyms_search.module, line 25
Provides synonyms integration with searching.

Code

function synonyms_search_taxonomy_term_update($term) {

  // If we notice at least some change in synonyms of this term, we want to
  // trigger search re-indexing of nodes, where this term is referenced, since
  // change in term synonyms affects nodes ranking in the search.
  if (isset($term->original)) {
    $bundle = field_extract_bundle('taxonomy_term', $term);
    $behavior_implementations = synonyms_behavior_get('search', 'taxonomy_term', $bundle, TRUE);
    $current_search_synonyms = array();
    $previous_search_synonyms = array();
    foreach ($behavior_implementations as $behavior_implementation) {
      $current_search_synonyms = array_merge($current_search_synonyms, $behavior_implementation['object']
        ->extractSynonyms($term));
      $previous_search_synonyms = array_merge($previous_search_synonyms, $behavior_implementation['object']
        ->extractSynonyms($term->original));
    }
    $diff = array_diff($current_search_synonyms, $previous_search_synonyms);
    if (!empty($diff) || count($current_search_synonyms) != count($previous_search_synonyms)) {
      module_load_include('inc', 'synonyms_search', 'synonyms_search.pages');
      synonyms_search_reindex_nodes_by_terms(array(
        $term->tid,
      ));
    }
  }
}