function apachesolr_entity_fields in Apache Solr Search 7
Same name and namespace in other branches
- 8 apachesolr.module \apachesolr_entity_fields()
- 6.3 apachesolr.module \apachesolr_entity_fields()
Returns array containing information about node fields that should be indexed
3 calls to apachesolr_entity_fields()
- apachesolr_entity_field_facets in ./
apachesolr.module - Returns an array of facets for the provided entity type's fields.
- apachesolr_field_name_map in ./
apachesolr.module - Try to map a schema field name to a human-readable description.
- field_apachesolr_index_document_build in ./
apachesolr.module - Implements hook_apachesolr_index_document_build().
File
- ./
apachesolr.module, line 2115 - Integration with the Apache Solr search application.
Code
function apachesolr_entity_fields($entity_type = 'node') {
$fields =& drupal_static(__FUNCTION__, array());
if (!isset($fields[$entity_type])) {
$fields[$entity_type] = array();
// Get the field mappings from apachesolr_field_mappings() implementations.
$mappings = apachesolr_get_field_mappings($entity_type);
$modules = system_get_info('module');
$instances = field_info_instances($entity_type);
foreach (field_info_fields() as $field_name => $field) {
$row = array();
if (isset($field['bundles'][$entity_type]) && (isset($mappings['per-field'][$field_name]) || isset($mappings[$field['type']]))) {
// Find the mapping.
if (isset($mappings['per-field'][$field_name])) {
$row = $mappings['per-field'][$field_name];
}
else {
$row = $mappings[$field['type']];
}
// The field info array.
$row['field'] = $field;
// Cardinality: The number of values the field can hold. Legal values
// are any positive integer or FIELD_CARDINALITY_UNLIMITED.
if ($row['field']['cardinality'] != 1) {
$row['multiple'] = TRUE;
}
// @todo: for fields like taxonomy we are indexing multiple Solr fields
// per entity field, but are keying on a single Solr field name here.
$function = !empty($row['name callback']) ? $row['name callback'] : NULL;
if ($function && is_callable($function)) {
$row['name'] = $function($field);
}
else {
$row['name'] = $field['field_name'];
}
$row['module_name'] = $modules[$field['module']]['name'];
// Set display name
$display_name = array();
foreach ($field['bundles'][$entity_type] as $bundle) {
$field_display = isset($instances[$bundle][$field_name]['display']) ? $instances[$bundle][$field_name]['display'] : array();
if (empty($field_display['search_index']) || isset($field_display['search_index']['type']) && $field_display['search_index']['type'] != 'hidden') {
$row['display_name'] = $instances[$bundle][$field_name]['label'];
$row['bundles'][] = $bundle;
}
}
// Only add to the $fields array if some instances are displayed for the search index.
if (!empty($row['bundles'])) {
// Use the Solr index key as the array key.
$fields[$entity_type][apachesolr_index_key($row)][] = $row;
}
}
}
}
return $fields[$entity_type];
}