protected function SearchApiDenormalizedEntityGrouping::getSupportedFields in Search API Grouping 7.2
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 SearchApiDenormalizedEntityGrouping::getSupportedFields()
- SearchApiDenormalizedEntityGrouping::configurationForm in includes/
processor_grouping.inc - Return the settings form for this processor.
File
- includes/
processor_grouping.inc, line 117 - Processor for grouping support.
Class
- SearchApiDenormalizedEntityGrouping
- 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'),
'search_api_relevance' => t('Score/Relevance'),
),
'default_fields' => array(),
);
// Adding random sorting, if server supports it.
if ($this->index
->server()
->supportsFeature('search_api_random_sort')) {
$supported_fields['field_sorts']['search_api_random'] = t('Random sorting');
}
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') {
$conversion_msg = $field['type'] != 'string' ? ' (' . t('Converted to string for indexing') . ')' : NULL;
$supported_fields['field_options'][$name] = $field['name'] . $conversion_msg;
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;
}