function apachesolr_entity_fields in Apache Solr Search 6.3
Same name and namespace in other branches
- 8 apachesolr.module \apachesolr_entity_fields()
- 7 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.
- content_apachesolr_index_document_build in ./
apachesolr.module - Implements hook_apachesolr_index_document_build() on behalf of content module.
File
- ./
apachesolr.module, line 2058 - Integration with the Apache Solr search application.
Code
function apachesolr_entity_fields($entity_type = 'node') {
static $fields = 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);
// Only CCK can add extra fields so we don't support anything if we do not
// have CCK
if (module_exists('content')) {
//$modules = system_get_info('module');
foreach (content_fields() as $field_name => $field) {
$row = array();
if (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;
// @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'] = $field['widget']['module'];
// Get content types which use this field.
$result = db_query("SELECT nt.type FROM {" . content_instance_tablename() . "} nfi " . "LEFT JOIN {node_type} nt ON nt.type = nfi.type_name " . "WHERE nfi.field_name = '%s' " . "AND nfi.widget_active = 1", $field['field_name']);
// Display this field if at least one content type which uses the
// field does not exclude it from the search index.
// In the worst case it's empty, but field values are still rendered.
while ($type = db_fetch_array($result)) {
$bundle = content_types($type['type']);
$field_display = isset($bundle['fields'][$field_name]['display_settings']) ? $bundle['fields'][$field_name]['display_settings'] : array();
if (empty($field_display[NODE_BUILD_SEARCH_INDEX]) || !$field_display[NODE_BUILD_SEARCH_INDEX]['exclude'] && $field_display[NODE_BUILD_SEARCH_INDEX]['format'] != 'hidden') {
$row['display_name'] = $bundle['fields'][$field_name]['widget']['label'];
$row['bundles'][] = $bundle['fields'][$field_name]['type_name'];
}
}
// 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;
}
}
}
}
// Construct pseudo-fields for taxonomy
if (module_exists('taxonomy')) {
foreach (taxonomy_get_vocabularies() as $vid => $vocabulary) {
//@todo: think $row should be renamed to $field and $field to $field_info, $row is confusing, but this should be done in d7 and back-ported
//@todo: remove this and the above comment before commit
$field = $mappings['taxonomy_term'];
$field['name'] = 'taxonomy_vid_' . $vid;
$field['module_name'] = $vocabulary->module;
$field['display_name'] = $vocabulary->name;
$field['bundles'] = $vocabulary->nodes;
$field['multiple'] = true;
// Faux field-info
$field['field'] = array();
$field['field']['field_name'] = 'taxonomy';
$field['field']['vid'] = $vid;
$field['field']['type'] = 'taxonomy_term';
if (!empty($field['bundles'])) {
$fields[$entity_type][apachesolr_index_key($field)] = array(
$field,
);
}
}
}
}
return $fields[$entity_type];
}