You are here

function apachesolr_cck_fields in Apache Solr Search 6

Same name and namespace in other branches
  1. 5.2 apachesolr.module \apachesolr_cck_fields()
  2. 5 apachesolr.module \apachesolr_cck_fields()
  3. 6.2 apachesolr.module \apachesolr_cck_fields()

Invokes hook_apachesolr_cck_fields_alter() to find out how to handle CCK fields.

5 calls to apachesolr_cck_fields()
apachesolr_node_to_document in ./apachesolr.index.inc
Given a node ID, return a document representing that node.
apachesolr_search_apachesolr_facets in ./apachesolr_search.module
Implementation of hook_apachesolr_facets().
apachesolr_search_block in ./apachesolr_search.module
Implementation of hook_block().
apachesolr_search_update_6001 in ./apachesolr_search.install
Update to block deltas.
_apachesolr_field_name_map in ./apachesolr.admin.inc
Try to map a schema field name to a human-readable description.

File

./apachesolr.module, line 1540
Integration with the Apache Solr search application.

Code

function apachesolr_cck_fields() {
  static $fields;
  if (!isset($fields)) {
    $fields = array();

    // If CCK isn't enabled, do nothing.
    if (module_exists('content')) {
      module_load_include('inc', 'content', 'includes/content.crud');
      $cck_field_instances = content_field_instance_read();

      // A single default mapping for all text fields using optionwidgets.
      $mappings['text'] = array(
        'optionwidgets_select' => array(
          'callback' => '',
          'index_type' => 'string',
          'facets' => TRUE,
        ),
        'optionwidgets_buttons' => array(
          'callback' => '',
          'index_type' => 'string',
          'facets' => TRUE,
        ),
        'optionwidgets_onoff' => array(
          'callback' => '',
          'index_type' => 'string',
          'facets' => TRUE,
        ),
      );

      // A single default mapping for all integer fields using optionwidgets.
      $mappings['number_integer'] = array(
        'optionwidgets_select' => array(
          'callback' => '',
          'index_type' => 'sint',
          'facets' => TRUE,
        ),
        'optionwidgets_buttons' => array(
          'callback' => '',
          'index_type' => 'sint',
          'facets' => TRUE,
        ),
        'optionwidgets_onoff' => array(
          'callback' => '',
          'index_type' => 'sint',
          'facets' => TRUE,
        ),
      );

      // A field-specific mapping would look like:
      // $mappings['per-field']['field_model_name'] = array('callback' => '', 'index_type' => 'string', 'facets' => TRUE);
      // or
      // $mappings['per-field']['field_model_price'] = array('callback' => '', 'index_type' => 'float', 'facets' => TRUE);
      // Allow other modules to add or alter mappings.
      drupal_alter('apachesolr_cck_fields', $mappings);
      foreach ($cck_field_instances as $instance) {
        $field_type = $instance['type'];
        $field_name = $instance['field_name'];
        $widget_type = $instance['widget']['type'];

        // Only deal with fields that have index mappings and that have not been marked for exclusion.
        if ((isset($mappings[$field_type][$widget_type]) || isset($mappings['per-field'][$field_name])) && empty($instance['display_settings'][NODE_BUILD_SEARCH_INDEX]['exclude'])) {
          if (isset($mappings['per-field'][$field_name])) {
            $instance['index_type'] = $mappings['per-field'][$field_name]['index_type'];
            $instance['callback'] = $mappings['per-field'][$field_name]['callback'];

            // Default 'facets' to TRUE for backwards compatibility.
            $instance['facets'] = isset($mappings['per-field'][$field_name]['facets']) ? $mappings['per-field'][$field_name]['facets'] : TRUE;
          }
          else {
            $instance['index_type'] = $mappings[$field_type][$widget_type]['index_type'];
            $instance['callback'] = $mappings[$field_type][$widget_type]['callback'];

            // Default 'facets' to TRUE for backwards compatibility.
            $instance['facets'] = isset($mappings[$field_type][$widget_type]['facets']) ? $mappings[$field_type][$widget_type]['facets'] : TRUE;
          }
          $instance['multiple'] = (bool) $instance['multiple'];
          $instance['name'] = 'cck_' . $field_name;
          if (isset($fields[$field_name]) && is_array($fields[$field_name])) {

            // Merge together settings when used for multiple node types.
            $fields[$field_name] = array_merge($fields[$field_name], $instance);
          }
          else {
            $fields[$field_name] = $instance;
          }
          $fields[$field_name]['content_types'][] = $instance['type_name'];
          unset($fields[$field_name]['type_name']);
        }
      }
    }
  }
  return $fields;
}