search.install 5.2 KB

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