You are here

function apachesolr_add_taxonomy_to_document in Apache Solr Search 5.2

Same name and namespace in other branches
  1. 6 apachesolr.index.inc \apachesolr_add_taxonomy_to_document()
  2. 6.2 apachesolr.index.inc \apachesolr_add_taxonomy_to_document()

Extract taxonomy from $node and add to dynamic fields.

1 call to apachesolr_add_taxonomy_to_document()
apachesolr_node_to_document in ./apachesolr.index.inc
Given a node ID, return a document representing that node.

File

./apachesolr.index.inc, line 166
Functions used when indexing content to Apache Solr.

Code

function apachesolr_add_taxonomy_to_document(&$document, $node) {
  if (isset($node->taxonomy) && is_array($node->taxonomy)) {
    foreach ($node->taxonomy as $term) {

      // Double indexing of tids lets us do effecient searches (on tid)
      // and do accurate per-vocabulary faceting.
      // By including the ancestors to a term in the index we make
      // sure that searches for general categories match specific
      // categories, e.g. Fruit -> apple, a search for fruit will find
      // content categorized with apple.
      $ancestors = taxonomy_get_parents_all($term->tid);
      foreach ($ancestors as $ancestor) {
        $document
          ->setMultiValue('tid', $ancestor->tid);
        $document
          ->setMultiValue('im_vid_' . $ancestor->vid, $ancestor->tid);
        $name = apachesolr_clean_text($ancestor->name);
        $document
          ->setMultiValue('vid', $ancestor->vid);
        $document->{'ts_vid_' . $ancestor->vid . '_names'} .= ' ' . $name;

        // We index each name as a string for cross-site faceting
        // using the vocab name rather than vid in field construction .
        $document
          ->setMultiValue('sm_vid_' . apachesolr_vocab_name($ancestor->vid), $name);
      }
    }
  }
}