public function SearchApiGroupingMultivalueField::preprocessIndexItems in Search API Grouping 7
Splits up the items on behalf of a multivalue field.
Overrides SearchApiAbstractProcessor::preprocessIndexItems
File
- includes/
processor_multivalue_field.inc, line 38 - Processor for splitting indexing items on behalf of a multivalue field.
Class
- SearchApiGroupingMultivalueField
- Processor for splitting up items on behalf of a multivalue field.
Code
public function preprocessIndexItems(array &$items) {
// Preprocess first.
parent::preprocessIndexItems($items);
$source_items = $items;
$all_items = array();
if (!empty($this->options['split_field'])) {
foreach ($items as $id => $item) {
// Find the properties of the split field.
$field_properties = array();
list($key, $property) = explode(':', $this->options['split_field']);
foreach ($item as $related_name => $related_field) {
if (substr($related_name, 0, mb_strlen($key) + 1) == $key . ':') {
$field_properties[] = $related_name;
}
}
// Split field and properties found.
if (!empty($field_properties)) {
foreach ($item[$this->options['split_field']]['value'] as $delta => $value) {
$split_item = $item;
foreach ($field_properties as $field_property) {
if (search_api_is_list_type($item[$field_property]['type'])) {
$split_item[$field_property]['value'] = array(
$item[$field_property]['value'][$delta],
);
}
else {
// Very unlikely case but it's better to cover it.
$split_item[$field_property]['value'] = $item[$field_property]['value'];
}
}
$all_items[$id . ':delta' . $delta] = $split_item;
}
}
else {
$all_items[$id] = $item;
}
}
}
$items = $all_items;
}