search.install 5.2 KB

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