function apachesolr_cck_fields in Apache Solr Search 5.2
Same name and namespace in other branches
- 5 apachesolr.module \apachesolr_cck_fields()
- 6 apachesolr.module \apachesolr_cck_fields()
- 6.2 apachesolr.module \apachesolr_cck_fields()
Invokes hook_apachesolr_cck_field_mappings to find out how to handle CCK fields.
6 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_5001 in ./
apachesolr_search.install - Update to block deltas.
- theme_apachesolr_breadcrumb_cck in ./
apachesolr_search.module
File
- ./
apachesolr.module, line 1402 - Integration with the Apache Solr search application.
Code
function apachesolr_cck_fields($field = NULL, $reset = FALSE) {
static $fields;
if (!isset($fields) || $reset) {
if (!$reset && ($cache = cache_get('cck_fields', 'cache_apachesolr'))) {
$fields = unserialize($cache->data);
}
else {
$fields = array();
// If CCK isn't enabled, do nothing.
if (module_exists('content')) {
// A single default mapping for all text fields.
$mappings['text'] = array(
'options_select' => array(
'indexing_callback' => '',
'display_callback' => 'apachesolr_cck_text_field_callback',
'index_type' => 'string',
),
'options_buttons' => array(
'indexing_callback' => '',
'display_callback' => 'apachesolr_cck_text_field_callback',
'index_type' => 'string',
),
);
$mappings['nodereference'] = array(
'nodereference_select' => array(
'display_callback' => 'apachesolr_cck_nodereference_field_callback',
'index_type' => 'integer',
),
'nodereference_autocomplete' => array(
'display_callback' => 'apachesolr_cck_nodereference_field_callback',
'index_type' => 'integer',
),
);
$mappings['userreference'] = array(
'userreference_select' => array(
'display_callback' => 'apachesolr_cck_userreference_field_callback',
'index_type' => 'integer',
),
'userreference_autocomplete' => array(
'display_callback' => 'apachesolr_cck_userreference_field_callback',
'index_type' => 'integer',
),
);
// A field-specific mapping would look like:
// $mappings['per-field']['field_model_name'] = array('callback' => '', 'index_type' => 'string');
// or
// $mappings['per-field']['field_model_price'] = array('callback' => '', 'index_type' => 'float');
// Allow other modules to add or alter mappings.
drupal_alter('apachesolr_cck_fields', $mappings);
$result = db_query("SELECT i.field_name, f.multiple, f.type AS field_type, i.widget_type, i.label, i.type_name AS content_type FROM {node_field_instance} i INNER JOIN {node_field} f ON i.field_name = f.field_name;");
while ($row = db_fetch_object($result)) {
// Only deal with fields that have option widgets (facets
// don't make sense otherwise), or fields that have specific mappings.
if (isset($mappings[$row->field_type][$row->widget_type]) || isset($mappings['per-field'][$row->field_name])) {
if (isset($mappings['per-field'][$row->field_name])) {
$row->index_type = $mappings['per-field'][$row->field_name]['index_type'];
$row->indexing_callback = $mappings['per-field'][$row->field_name]['indexing_callback'];
$row->display_callback = $mappings['per-field'][$row->field_name]['display_callback'];
}
else {
$row->index_type = $mappings[$row->field_type][$row->widget_type]['index_type'];
$row->indexing_callback = $mappings[$row->field_type][$row->widget_type]['indexing_callback'];
$row->display_callback = $mappings[$row->field_type][$row->widget_type]['display_callback'];
}
$row->multiple = (bool) $row->multiple;
// It's important that we put the 'cck_' here because several points in the later processing
// depend on it to route program flow to cck specific handlers.
$row->name = 'cck_' . $row->field_name;
$fields[$row->field_name] = array_merge((array) $fields[$row->field_name], (array) $row);
$fields[$row->field_name]['content types'][] = $row->content_type;
unset($fields[$row->field_name]['content_type']);
}
}
}
cache_set('cck_fields', 'cache_apachesolr', serialize($fields));
}
}
return is_null($field) ? $fields : $fields[$field];
}