/[drupal]/contributions/modules/field_indexer/cck_field_indexer.module
ViewVC logotype

Contents of /contributions/modules/field_indexer/cck_field_indexer.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download) (as text)
Mon May 26 21:02:49 2008 UTC (18 months ago) by davidlesieur
Branch: MAIN
CVS Tags: DRUPAL-6--1-0, DRUPAL-5--1-0, HEAD
Branch point for: DRUPAL-5
Changes since 1.1: +6 -5 lines
File MIME type: text/x-php
Support multiple-value fields.
1 <?php
2 // $Id: cck_field_indexer.module,v 1.1 2008/05/19 01:33:22 davidlesieur Exp $
3
4 /**
5 * @file
6 * Exposes CCK fields for indexing into the search index.
7 */
8
9 /**
10 * Implementation of hook_field_indexer_list().
11 *
12 * Retrieve all fields provided by CCK.
13 *
14 * @return
15 * An array describing the fields, each field being represented by an array
16 * with the following attributes:
17 * - name: Machine name or id of the field.
18 * - extra_name: Extra field name or id information.
19 * - label: Printable name of the field.
20 * - help: Optional info that may help in identifying the field.
21 */
22 function cck_field_indexer_field_indexer_list() {
23 $cck_fields = content_fields();
24 $fields = array();
25 foreach ($cck_fields as $field) {
26 $fields[] = array(
27 'namespace' => 'cck',
28 'name' => $field['field_name'],
29 'extra_name' => '',
30 'label' => $field['widget']['label'],
31 'help' => $field['field_name'],
32 );
33 }
34 return $fields;
35 }
36
37 /**
38 * Implementation of hook_nodeapi().
39 *
40 * This is used to add our own entries to the search index. Using nodeapi's
41 * update index operation is convenient, since the node module already handles
42 * the logic for determining which nodes need indexing.
43 */
44 function cck_field_indexer_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
45 static $fields = NULL;
46 if ($op == 'update index') {
47 if (!isset($fields)) {
48 $fields = field_indexer_load_fields(TRUE, 'cck');
49 }
50 $type = content_types($node->type);
51 foreach ($fields as $field) {
52 if (isset($type['fields'][$field['name']]) && isset($node->{$field['name']})) {
53 $value = '';
54 foreach ($node->{$field['name']} as $item) {
55 $value .= ' '. content_format($type['fields'][$field['name']], $item, 'default', $node);
56 }
57 if (trim($value) != '') {
58 field_indexer_index($node->nid, $field['fiid'], $value);
59 }
60 }
61 }
62 }
63 }
64

  ViewVC Help
Powered by ViewVC 1.1.2