如何在solr:drupal6中索引文本区域的cck字段

时间:2009-09-25 10:59:05

标签: drupal-6 solr

我创建了一个类型为 textarea 的cck字段,名称为 filed_desc ,如何让这个字段在solr中编入索引。

我发现了这篇文章http://acquia.com/blog/understanding-apachesolr-cck-api,我试过这个,但它没有索引该文件,可以有人帮忙。

    <?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 个答案:

答案 0 :(得分:1)

我目前正在以漂亮,漂亮,通用的方式添加它。如果您现在确实需要这项工作,请查看Drupal.org上的this issue。我的代码目前生活在GitHub,但希望我可以将其包含在上游并发布它。

希望有所帮助!

答案 1 :(得分:0)

每个字段映射更容易控制。

改变功能:

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

回调:

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