You are here

protected function SearchApiGroupingGrouping::getSupportedFields in Search API Grouping 7

Returns an array of supported fields to choose of.

This function respects the server behind the index to provide only valid fields.

Return value

array An associative array with child arrays for the supported fields for each feature: array( 'field_options' => array(), 'field_sorts' => array(), 'field' => array(), );

1 call to SearchApiGroupingGrouping::getSupportedFields()
SearchApiGroupingGrouping::configurationForm in includes/processor_grouping.inc
Return the settings form for this processor.

File

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

Class

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

Code

protected function getSupportedFields() {
  $this->index
    ->server()->class;
  $fields = $this->index
    ->getFields();
  $supported_fields = array(
    'field_options' => array(),
    'field_sorts' => array(
      '' => t('None'),
      'score' => t('Score/Relevance'),
    ),
    'default_fields' => array(),
  );
  if (isset($this->options['fields'])) {
    $supported_fields['default_fields'] = drupal_map_assoc(array_keys($this->options['fields']));
  }
  foreach ($fields as $name => $field) {

    // We can only rely on indexed fields.
    if ($field['indexed']) {

      // @TODO Add other supported servers.
      switch (TRUE) {

        // Apache solr server.
        case $this->index
          ->server()->class == 'search_api_solr_service' || is_subclass_of($this->index
          ->server()->class, 'search_api_solr_service'):

        // Currently Solr is only compatible with single valued, indexed,
        // string/integer fields.
        default:
          if (!search_api_is_list_type($field['type'])) {
            if ($field['type'] == 'string' || $field['type'] == 'integer') {
              $supported_fields['field_options'][$name] = $field['name'];
              if (!empty($default_fields[$name]) || !isset($this->options['fields']) && $this
                ->testField($name, $field)) {
                $supported_fields['default_fields'][$name] = $name;
              }
            }

            // We can only sort according to single-valued fields.
            if ($field['type'] == search_api_extract_inner_type($field['type'])) {
              $supported_fields['field_sorts'][$name] = $field['name'];
            }
          }
          break;
      }
    }
  }
  return $supported_fields;
}