function apachesolr_add_taxonomy_to_document in Apache Solr Search 6
Same name and namespace in other branches
- 5.2 apachesolr.index.inc \apachesolr_add_taxonomy_to_document()
- 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 167 - Functions used when indexing content to Apache Solr.
Code
function apachesolr_add_taxonomy_to_document($document, $node) {
static $ancestors = array();
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.
if (!isset($ancestors[$term->tid])) {
$ancestors[$term->tid] = taxonomy_get_parents_all($term->tid);
}
foreach ($ancestors[$term->tid] 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);
$ts_vid = 'ts_vid_' . $ancestor->vid . '_names';
$document->{$ts_vid} = isset($document->{$ts_vid}) ? $document->{$ts_vid} . ' ' . $name : $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);
}
}
}
}