Project

General

Profile

Paste
Download (5.24 KB) Statistics
| Branch: | Revision:

root / drupal7 / modules / search / search.install @ 27e02aed

1
<?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
  variable_del('search_logging');
16
}
17

    
18
/**
19
 * Implements hook_schema().
20
 */
21
function search_schema() {
22
  $schema['search_dataset'] = array(
23
    'description' => 'Stores items that will be searched.',
24
    'fields' => array(
25
      'sid' => array(
26
        'type' => 'int',
27
        'unsigned' => TRUE,
28
        'not null' => TRUE,
29
        'default' => 0,
30
        'description' => 'Search item ID, e.g. node ID for nodes.',
31
      ),
32
      'type' => array(
33
        'type' => 'varchar',
34
        'length' => 16,
35
        'not null' => TRUE,
36
        'description' => 'Type of item, e.g. node.',
37
      ),
38
      'data' => array(
39
        'type' => 'text',
40
        'not null' => TRUE,
41
        'size' => 'big',
42
        'description' => 'List of space-separated words from the item.',
43
      ),
44
      'reindex' => array(
45
        'type' => 'int',
46
        'unsigned' => TRUE,
47
        'not null' => TRUE,
48
        'default' => 0,
49
        'description' => 'Set to force node reindexing.',
50
      ),
51
    ),
52
    'primary key' => array('sid', 'type'),
53
  );
54

    
55
  $schema['search_index'] = array(
56
    'description' => 'Stores the search index, associating words, items and scores.',
57
    'fields' => array(
58
      'word' => array(
59
        'type' => 'varchar',
60
        'length' => 50,
61
        'not null' => TRUE,
62
        'default' => '',
63
        'description' => 'The {search_total}.word that is associated with the search item.',
64
      ),
65
      'sid' => array(
66
        'type' => 'int',
67
        'unsigned' => TRUE,
68
        'not null' => TRUE,
69
        'default' => 0,
70
        'description' => 'The {search_dataset}.sid of the searchable item to which the word belongs.',
71
      ),
72
      'type' => array(
73
        'type' => 'varchar',
74
        'length' => 16,
75
        'not null' => TRUE,
76
        'description' => 'The {search_dataset}.type of the searchable item to which the word belongs.',
77
      ),
78
      'score' => array(
79
        'type' => 'float',
80
        'not null' => FALSE,
81
        'description' => 'The numeric score of the word, higher being more important.',
82
      ),
83
    ),
84
    'indexes' => array(
85
      'sid_type' => array('sid', 'type'),
86
    ),
87
    'foreign keys' => array(
88
      'search_dataset' => array(
89
        'table' => 'search_dataset',
90
        'columns' => array(
91
          'sid' => 'sid',
92
          'type' => 'type',
93
        ),
94
      ),
95
    ),
96
    'primary key' => array('word', 'sid', 'type'),
97
  );
98

    
99
  $schema['search_total'] = array(
100
    'description' => 'Stores search totals for words.',
101
    'fields' => array(
102
      'word' => array(
103
        'description' => 'Primary Key: Unique word in the search index.',
104
        'type' => 'varchar',
105
        'length' => 50,
106
        'not null' => TRUE,
107
        'default' => '',
108
      ),
109
      'count' => array(
110
        'description' => "The count of the word in the index using Zipf's law to equalize the probability distribution.",
111
        'type' => 'float',
112
        'not null' => FALSE,
113
      ),
114
    ),
115
    'primary key' => array('word'),
116
  );
117

    
118
  $schema['search_node_links'] = array(
119
    'description' => 'Stores items (like nodes) that link to other nodes, used to improve search scores for nodes that are frequently linked to.',
120
    'fields' => array(
121
      'sid' => array(
122
        'type' => 'int',
123
        'unsigned' => TRUE,
124
        'not null' => TRUE,
125
        'default' => 0,
126
        'description' => 'The {search_dataset}.sid of the searchable item containing the link to the node.',
127
      ),
128
      'type' => array(
129
        'type' => 'varchar',
130
        'length' => 16,
131
        'not null' => TRUE,
132
        'default' => '',
133
        'description' => 'The {search_dataset}.type of the searchable item containing the link to the node.',
134
      ),
135
      'nid' => array(
136
        'type' => 'int',
137
        'unsigned' => TRUE,
138
        'not null' => TRUE,
139
        'default' => 0,
140
        'description' => 'The {node}.nid that this item links to.',
141
      ),
142
      'caption' => array(
143
        'type' => 'text',
144
        'size' => 'big',
145
        'not null' => FALSE,
146
        'description' => 'The text used to link to the {node}.nid.',
147
      ),
148
    ),
149
    'primary key' => array('sid', 'type', 'nid'),
150
    'indexes' => array(
151
      'nid' => array('nid'),
152
    ),
153
  );
154

    
155
  return $schema;
156
}
157

    
158
/**
159
 * Replace unique keys in 'search_dataset' and 'search_index' by primary keys.
160
 */
161
function search_update_7000() {
162
  db_drop_unique_key('search_dataset', 'sid_type');
163
  $dataset_type_spec = array(
164
    'type' => 'varchar',
165
    'length' => 16,
166
    'not null' => TRUE,
167
    'description' => 'Type of item, e.g. node.',
168
  );
169
  db_change_field('search_dataset', 'type', 'type', $dataset_type_spec);
170
  db_add_primary_key('search_dataset', array('sid', 'type'));
171

    
172
  db_drop_index('search_index', 'word');
173
  db_drop_unique_key('search_index', 'word_sid_type');
174
  $index_type_spec = array(
175
    'type' => 'varchar',
176
    'length' => 16,
177
    'not null' => TRUE,
178
    'description' => 'The {search_dataset}.type of the searchable item to which the word belongs.',
179
  );
180
  db_change_field('search_index', 'type', 'type', $index_type_spec);
181
  db_add_primary_key('search_index', array('word', 'sid', 'type'));
182
}
183