Hi,

Can some body help me? Is the code below correct for a my module?
When i test the code I get wrong content on fields.

Thanks,

Massimo

function wart_apachesolr_cck_fields_alter(&$mappings) {
// $mappings = array();
$mappings['per-field']['field_url'] = array(
'index_type' => 'string',
'callback' => 'wart_solr_callback',
'facet' => FALSE,
);
$mappings['per-field']['field_favicon_url'] = array(
'index_type' => 'string',
'callback' => 'wart_solr_callback',
'facet' => FALSE,
);
$mappings['per-field']['field_combined_rank'] = array(
'index_type' => 'sfloat',
'callback' => 'wart_solr_callback',
'facet' => FALSE,
);

$mappings['per-field']['field_alexa_rank'] = array(
'index_type' => 'integer',
'callback' => 'wart_solr_callback',
'facet' => FALSE,
);
$mappings['per-field']['field_alexa_data_url'] = array(
'index_type' => 'text',
'callback' => 'wart_solr_callback',
'facet' => FALSE,
);
}

Comments

maxmic’s picture

Title: How to add cck fields? any example? » How to add cck fields? any working example?
shaneonabike’s picture

Issue tags: +CCK, +alter, +ApacheSolr, +integer, +hooks (duplicate)

This is what I did for a project that I am currently working on. This integrates the integer CCK field (generally speaking the latest code integrates the string CCK and taxonomy out of the box).

After developing some code for a website that we were building that required the integration of CCK types that were of type integer I thought I would post the following code to help others out.

CCK fields alter (CCK strings deal with these types out of the box but not for integers tragically)

function yourmodule_apachesolr_cck_fields_alter(&$mappings) {
  $mappings['number_integer'] = array(
   'optionwidgets_select' => array(
      // This function is called when teh facet is being indexed
      'indexing_callback' => 'yourmodule_cck_checklist_indexing_callback',
      // This function will get called when the facet links are displayed
      // in facet blocks at search time.
      'display_callback' => 'yourmodule_cck_checklist_display_callback',
     'index_type' => 'integer'),
   'optionwidgets_buttons' => array(
      'indexing_callback' => 'yourmodule_cck_checklist_indexing_callback',
      // This function will get called when the facet links are displayed
      // in facet blocks at search time.
      'display_callback' => 'olesolr_cck_checklist_display_callback',
      'index_type' => 'integer'),
  );
  return $mappings;
}

Next function renders the checklist block

function olesolr_cck_checklist_indexing_callback($node, $field_name, $cck_info) {
  // $fields is an array because we send back a key => value pair for every
  // value of the field.
  $fields = array();

  // Don't do anything if this node doesn't have this field.
  if (isset($node->$field_name)) {
    // Get the index key based on the $cck_info.
    $index_key = apachesolr_index_key($cck_info);
    //dsm($index_key);

    // Go through each item and setup the appropriate key
    foreach ($node->$field_name as $field) {
      foreach($field as $key => $value) {
        if ($index_value =  (isset($value) ? $value : FALSE)) {
          $fields[] = array(
            'key' => $index_key,
            'value' => $index_value,
          );
        }
      }
    }
  }
  return $fields;
}

Finally the display callback (which is pretty basic)

function yourmodule_cck_checklist_display_callback($facet, $options) {
  if (function_exists('content_format')) {
    return content_format($options['delta'], array('value' => $facet));
  }
  else {
    return $facet;
  }
}

jpmckinney’s picture

Status: Active » Fixed

This blog post has a good explanation of the API: http://acquia.com/blog/understanding-apachesolr-cck-api

Status: Fixed » Closed (fixed)
Issue tags: -CCK, -alter, -ApacheSolr, -integer, -hooks (duplicate)

Automatically closed -- issue fixed for 2 weeks with no activity.