public function SearchApiAlterAddAggregation::reduce in Search API 7
Helper method for reducing an array to a single value.
File
- includes/
callback_add_aggregation.inc, line 220 - Contains SearchApiAlterAddAggregation.
Class
- SearchApiAlterAddAggregation
- Search API data alteration callback that adds an URL field for all items.
Code
public function reduce($a, $b) {
switch ($this->reductionType) {
case 'fulltext':
return isset($a) ? $a . $this->fulltextReductionSeparator . $b : $b;
case 'sum':
return $a + $b;
case 'count':
return $a + 1;
case 'max':
return isset($a) ? max($a, $b) : $b;
case 'min':
return isset($a) ? min($a, $b) : $b;
case 'first':
return isset($a) ? $a : $b;
case 'first_char':
$b = "{$b}";
if (isset($a) || $b === '') {
return $a;
}
return drupal_substr($b, 0, 1);
case 'last':
return isset($b) ? $b : $a;
case 'list':
if (!isset($a)) {
$a = array();
}
$a[] = $b;
return $a;
}
return NULL;
}