search_api_combined.module in Search API Combined Fields 7
File
search_api_combined.module
View source
<?php
function search_api_combined_search_api_alter_callback_info() {
$callbacks['search_api_alter_add_combined'] = array(
'name' => t('Combined fields'),
'description' => t('Gives you the ability to define additional fields, combining data from one or more other fields.'),
'class' => 'SearchApiAlterAddCombined',
);
return $callbacks;
}
function search_api_combined_facetapi_facet_info_alter(array &$facet_info, array $searcher_info) {
$processor_info = search_api_get_processors();
$index = search_api_index_load($searcher_info['instance']);
$options = empty($index->options) ? array() : $index->options;
$callbacks = empty($options['data_alter_callbacks']) ? array() : $options['data_alter_callbacks'];
if (TRUE === isset($callbacks['search_api_alter_add_combined']['settings']['fields']) && 1 == $callbacks['search_api_alter_add_combined']['status']) {
foreach ($callbacks['search_api_alter_add_combined']['settings']['fields'] as $key => $combined) {
if (FALSE === empty($combined['imitate']) && TRUE === isset($facet_info[$combined['imitate']])) {
$facet_info[$key]['field type'] = $facet_info[$combined['imitate']]['field type'];
$facet_info[$key]['map options']['field'] = array_merge($facet_info[$key]['map options']['field'], $facet_info[$combined['imitate']]['map options']['field']);
}
foreach (array(
'values callback',
'hierarchy callback',
'map callback',
'min callback',
'max callback',
) as $callback) {
if (isset($facet_info[$combined['imitate']]) && $facet_info[$key][$callback] != $facet_info[$combined['imitate']][$callback]) {
$facet_info[$key][$callback] = $facet_info[$combined['imitate']][$callback];
}
}
}
}
}