Projet

Général

Profil

Paste
Télécharger (5,21 ko) Statistiques
| Branche: | Révision:

root / drupal7 / modules / search / search.install @ 134c7813

1 85ad3d82 Assos Assos
<?php
2
3
/**
4
 * @file
5
 * Install, update and uninstall functions for the search module.
6
 */
7
8
/**
9
 * Implements hook_uninstall().
10
 */
11
function search_uninstall() {
12
  variable_del('minimum_word_size');
13
  variable_del('overlap_cjk');
14
  variable_del('search_cron_limit');
15
}
16
17
/**
18
 * Implements hook_schema().
19
 */
20
function search_schema() {
21
  $schema['search_dataset'] = array(
22
    'description' => 'Stores items that will be searched.',
23
    'fields' => array(
24
      'sid' => array(
25
        'type' => 'int',
26
        'unsigned' => TRUE,
27
        'not null' => TRUE,
28
        'default' => 0,
29
        'description' => 'Search item ID, e.g. node ID for nodes.',
30
      ),
31
      'type' => array(
32
        'type' => 'varchar',
33
        'length' => 16,
34
        'not null' => TRUE,
35
        'description' => 'Type of item, e.g. node.',
36
      ),
37
      'data' => array(
38
        'type' => 'text',
39
        'not null' => TRUE,
40
        'size' => 'big',
41
        'description' => 'List of space-separated words from the item.',
42
      ),
43
      'reindex' => array(
44
        'type' => 'int',
45
        'unsigned' => TRUE,
46
        'not null' => TRUE,
47
        'default' => 0,
48
        'description' => 'Set to force node reindexing.',
49
      ),
50
    ),
51
    'primary key' => array('sid', 'type'),
52
  );
53
54
  $schema['search_index'] = array(
55
    'description' => 'Stores the search index, associating words, items and scores.',
56
    'fields' => array(
57
      'word' => array(
58
        'type' => 'varchar',
59
        'length' => 50,
60
        'not null' => TRUE,
61
        'default' => '',
62
        'description' => 'The {search_total}.word that is associated with the search item.',
63
      ),
64
      'sid' => array(
65
        'type' => 'int',
66
        'unsigned' => TRUE,
67
        'not null' => TRUE,
68
        'default' => 0,
69
        'description' => 'The {search_dataset}.sid of the searchable item to which the word belongs.',
70
      ),
71
      'type' => array(
72
        'type' => 'varchar',
73
        'length' => 16,
74
        'not null' => TRUE,
75
        'description' => 'The {search_dataset}.type of the searchable item to which the word belongs.',
76
      ),
77
      'score' => array(
78
        'type' => 'float',
79
        'not null' => FALSE,
80
        'description' => 'The numeric score of the word, higher being more important.',
81
      ),
82
    ),
83
    'indexes' => array(
84
      'sid_type' => array('sid', 'type'),
85
    ),
86
    'foreign keys' => array(
87
      'search_dataset' => array(
88
        'table' => 'search_dataset',
89
        'columns' => array(
90
          'sid' => 'sid',
91
          'type' => 'type',
92
        ),
93
      ),
94
    ),
95
    'primary key' => array('word', 'sid', 'type'),
96
  );
97
98
  $schema['search_total'] = array(
99
    'description' => 'Stores search totals for words.',
100
    'fields' => array(
101
      'word' => array(
102
        'description' => 'Primary Key: Unique word in the search index.',
103
        'type' => 'varchar',
104
        'length' => 50,
105
        'not null' => TRUE,
106
        'default' => '',
107
      ),
108
      'count' => array(
109
        'description' => "The count of the word in the index using Zipf's law to equalize the probability distribution.",
110
        'type' => 'float',
111
        'not null' => FALSE,
112
      ),
113
    ),
114
    'primary key' => array('word'),
115
  );
116
117
  $schema['search_node_links'] = array(
118
    'description' => 'Stores items (like nodes) that link to other nodes, used to improve search scores for nodes that are frequently linked to.',
119
    'fields' => array(
120
      'sid' => array(
121
        'type' => 'int',
122
        'unsigned' => TRUE,
123
        'not null' => TRUE,
124
        'default' => 0,
125
        'description' => 'The {search_dataset}.sid of the searchable item containing the link to the node.',
126
      ),
127
      'type' => array(
128
        'type' => 'varchar',
129
        'length' => 16,
130
        'not null' => TRUE,
131
        'default' => '',
132
        'description' => 'The {search_dataset}.type of the searchable item containing the link to the node.',
133
      ),
134
      'nid' => array(
135
        'type' => 'int',
136
        'unsigned' => TRUE,
137
        'not null' => TRUE,
138
        'default' => 0,
139
        'description' => 'The {node}.nid that this item links to.',
140
      ),
141
      'caption' => array(
142
        'type' => 'text',
143
        'size' => 'big',
144
        'not null' => FALSE,
145
        'description' => 'The text used to link to the {node}.nid.',
146
      ),
147
    ),
148
    'primary key' => array('sid', 'type', 'nid'),
149
    'indexes' => array(
150
      'nid' => array('nid'),
151
    ),
152
  );
153
154
  return $schema;
155
}
156
157
/**
158
 * Replace unique keys in 'search_dataset' and 'search_index' by primary keys.
159
 */
160
function search_update_7000() {
161
  db_drop_unique_key('search_dataset', 'sid_type');
162
  $dataset_type_spec = array(
163
    'type' => 'varchar',
164
    'length' => 16,
165
    'not null' => TRUE,
166
    'description' => 'Type of item, e.g. node.',
167
  );
168
  db_change_field('search_dataset', 'type', 'type', $dataset_type_spec);
169
  db_add_primary_key('search_dataset', array('sid', 'type'));
170
171
  db_drop_index('search_index', 'word');
172
  db_drop_unique_key('search_index', 'word_sid_type');
173
  $index_type_spec = array(
174
    'type' => 'varchar',
175
    'length' => 16,
176
    'not null' => TRUE,
177
    'description' => 'The {search_dataset}.type of the searchable item to which the word belongs.',
178
  );
179
  db_change_field('search_index', 'type', 'type', $index_type_spec);
180
  db_add_primary_key('search_index', array('word', 'sid', 'type'));
181
}