You are here

public function SearchApiGroupingGrouping::configurationForm in Search API Grouping 7

Return the settings form for this processor.

Overrides SearchApiAbstractProcessor::configurationForm

File

includes/processor_grouping.inc, line 23
Processor for grouping support.

Class

SearchApiGroupingGrouping
Processor for grouping up items on behalf of user defined fields.

Code

public function configurationForm() {
  $form = parent::configurationForm();
  $supported_fields = $this
    ->getSupportedFields();
  $form['fields'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Fields to collapse on'),
    '#options' => $supported_fields['field_options'],
    '#default_value' => $supported_fields['default_fields'],
    '#attributes' => array(
      'class' => array(
        'search-api-checkboxes-list',
      ),
    ),
    '#description' => t('Choose the fields upon which to collapse the results into groups. Note that while selecting multiple fields is technicially supported, it may result in unexpected behaviour.'),
  );

  // Apache solr specific options.
  if ($this->index
    ->server()->class == 'search_api_solr_service' || is_subclass_of($this->index
    ->server()->class, 'search_api_solr_service')) {
    $default_sort = isset($this->options['group_sort']) ? $this->options['group_sort'] : '';
    $form['group_sort'] = array(
      '#type' => 'select',
      '#title' => t('Group sort'),
      '#options' => $supported_fields['field_sorts'],
      '#default_value' => $default_sort,
      '#description' => t('Choose the field by to sort within each group, the groups themselves will be sorted by the main query sorts.'),
    );
    $default_sort_direction = isset($this->options['group_sort_direction']) ? $this->options['group_sort_direction'] : '';
    $form['group_sort_direction'] = array(
      '#type' => 'select',
      '#title' => t('Group sort direction'),
      '#options' => array(
        'asc' => t('Ascending'),
        'desc' => t('Descending'),
      ),
      '#default_value' => $default_sort_direction,
    );
    $default_truncate = isset($this->options['truncate']) ? $this->options['truncate'] : TRUE;
    $form['truncate'] = array(
      '#type' => 'checkbox',
      '#title' => t('Truncate results before facets'),
      '#description' => t('If checked, facet counts are based on the most relevant document of each group matching the query, otherwise they are calculated for all documents before grouping.'),
      '#default_value' => $default_truncate,
    );
  }
  return $form;
}