How to index cck field of type text area in solr: drupal6

I created a cck file of type textarea named filed_desc , how do I get this field to be indexed in solr.

I found this article http://acquia.com/blog/understanding-apachesolr-cck-api , I tried this but it doesn't index the filed, can anyone help.

    <?php
// $Id$
/**
* Implementation of hook_apachesolr_cck_fields_alter
*/
function example_apachesolr_cck_fields_alter(&$mappings) {
  // either for all CCK of a given field_type and widget option
  // 'filefield' is here the CCK field_type. Correlates to $field['field_type']
  $mappings['text'] = array(
    'text_textarea' => array('callback' => 'example_callback', 'index_type' => 'string'),

  );

}



/**
* A function that gets called during indexing.
* @node The current node being indexed
* @fieldname The current field being indexed
*
* @return an array of arrays. Each inner array is a value, and must be
* keyed 'value' => $value
*/
function example_callback($node, $fieldname) {
  $fields = array();
  foreach ($node->$fieldname as $field) {
    // In this case we are indexing the filemime type. While this technically
    // makes it possible that we could search for nodes based on the mime type
    // of their file fields, the real purpose is to have facet blocks during
    // searching.
    $fields[] = array('value' => $field['field_desc']);
  }
  return $fields;
}

?>

      

+2


source to share


2 answers


I am currently working on adding this in a nice, nice, general way. If you really need this work, take a look at this issue at Drupal.org. My code currently lives on GitHub , although hopefully I can upstream this and make it a release.



Hope it helps!

+1


source


Easier to manage field mapping.

change function:

$mappings['per-field']['field_specialities'] = array(
  'index_type' => 'string',
  'callback' => 'ge_search_apachesolr_field_specialities_callback'
);

      



Callback:

function ge_search_apachesolr_field_specialities_callback($node, $fieldname)
{
  $fields = array();
  foreach($node->$fieldname as $field) {
    $fields[] = array('value' => $field['value']);
  }
  return $fields;
}

      

0


source







All Articles