2

我创建了一个名称为filed_desc 的文本区域类型的cck字段,我如何让这个字段在 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;
}

?>
4

2 回答 2

1

我目前正在努力以一种漂亮、漂亮、通用的方式添加它。如果您现在真的需要这项工作,请查看 Drupal.org 上的这个问题。我的代码目前在GitHub 上,但希望我可以将它包含在上游并发布它。

希望有帮助!

于 2010-02-23T09:21:00.530 回答
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;
}
于 2011-11-28T10:06:51.730 回答