【问题标题】:how to index cck field of type text area in solr: drupal6如何在solr中索引文本区域类型的cck字段:drupal6
【发布时间】:2009-09-25 10:59:04
【问题描述】:

我创建了一个类型为 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;
}

?>

【问题讨论】:

    标签: drupal-6 solr


    【解决方案1】:

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

    希望有帮助!

    【讨论】:

    • 最后怎么样了?线程中提到的要使用的补丁是哪个?您的代码是要保留一个单独的分支还是要添加回主要的 apachesolr 开发?
    【解决方案2】:

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

    修改函数:

    $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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-28
      • 1970-01-01
      • 2012-11-27
      • 1970-01-01
      • 1970-01-01
      • 2016-12-08
      • 2014-10-26
      相关资源
      最近更新 更多