You are here

public function SearchApiDenormalizedEntityGrouping::configurationForm in Search API Grouping 7.2

Return the settings form for this processor.

Overrides SearchApiAbstractProcessor::configurationForm

File

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

Class

SearchApiDenormalizedEntityGrouping
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_facetting = $this
      ->getFacettingBehavior();
    $form['facetting'] = array(
      '#type' => 'select',
      '#title' => t('Facetting behavior'),
      '#description' => t('Decide how facets should be handled for grouped results. Should the facets be based on the results that will be displayed to the user, or based on the just displayed result from each group of results, or should they ignore grouping and be based on the un-grouped results?'),
      '#options' => array(
        'results' => t('Based on the displayed groups'),
        'first_document' => t('Based on the first result of each group'),
        'documents' => t('Based on the un-grouped results'),
      ),
      '#default_value' => $default_facetting,
    );
    $form['group_limit'] = array(
      '#type' => 'textfield',
      '#title' => t('Results per group'),
      '#description' => t('The number of results are limited per group. By default, 1 result per group is returned.'),
      '#default_value' => isset($this->options['group_limit']) ? $this->options['group_limit'] : 1,
      '#element_validate' => array(
        'element_validate_integer_positive',
      ),
      '#size' => 3,
    );
  }
  return $form;
}