search.install 5.11 KB
Newer Older
1 2
<?php

3 4
/**
 * @file
5
 * Install, update, and uninstall functions for the Search module.
6 7
 */

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

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

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

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

158 159
  return $schema;
}
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176

/**
 * Update search module to use the configuration system.
 *
 * @ingroup config_upgrade
 */
function search_update_8000() {
  update_variables_to_config('search.settings', array(
   'minimum_word_size' => 'index.minimum_word_size',
   'overlap_cjk' => 'index.overlap_cjk',
   'search_cron_limit' => 'index.cron_limit',
   'search_tag_weights' => 'index.tag_weights',
   'search_active_modules' => 'active_modules',
   'search_and_or_limit' => 'and_or_limit',
   'search_default_module' => 'default_module',
  ));
}