public function SearchApiDenormalizedEntityGrouping::preprocessSearchQuery in Search API Grouping 7.2
Set the options so the server adapter can use the to implement grouping.
Overrides SearchApiAbstractProcessor::preprocessSearchQuery
File
- includes/
processor_grouping.inc, line 182 - Processor for grouping support.
Class
- SearchApiDenormalizedEntityGrouping
- Processor for grouping up items on behalf of user defined fields.
Code
public function preprocessSearchQuery(SearchApiQuery $query) {
$grouping_fields = $this
->getGroupingFields();
if (!empty($grouping_fields)) {
// We move the options from our options array into where the Solr Service
// is expecting them.
$options = array(
'use_grouping' => TRUE,
'fields' => $grouping_fields,
'group_sort' => array(),
'group_limit' => isset($this->options['group_limit']) ? $this->options['group_limit'] : NULL,
);
if (!empty($this->options['group_sort'])) {
$options['group_sort'][$this->options['group_sort']] = isset($this->options['group_sort_direction']) ? $this->options['group_sort_direction'] : 'asc';
}
switch ($this
->getFacettingBehavior()) {
case 'results':
$options += array(
'truncate' => FALSE,
'group_facet' => TRUE,
);
break;
case 'documents':
$options += array(
'truncate' => FALSE,
'group_facet' => FALSE,
);
break;
case 'first_document':
default:
$options += array(
'truncate' => TRUE,
'group_facet' => FALSE,
);
}
$query
->setOption('search_api_grouping', $options);
}
}