annotate core/modules/search/search.install @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 /**
Chris@0 4 * @file
Chris@0 5 * Install, update, and uninstall functions for the Search module.
Chris@0 6 */
Chris@0 7
Chris@0 8 /**
Chris@0 9 * Implements hook_schema().
Chris@0 10 */
Chris@0 11 function search_schema() {
Chris@0 12 $schema['search_dataset'] = [
Chris@0 13 'description' => 'Stores items that will be searched.',
Chris@0 14 'fields' => [
Chris@0 15 'sid' => [
Chris@0 16 'type' => 'int',
Chris@0 17 'unsigned' => TRUE,
Chris@0 18 'not null' => TRUE,
Chris@0 19 'default' => 0,
Chris@0 20 'description' => 'Search item ID, e.g. node ID for nodes.',
Chris@0 21 ],
Chris@0 22 'langcode' => [
Chris@0 23 'type' => 'varchar_ascii',
Chris@0 24 'length' => '12',
Chris@0 25 'not null' => TRUE,
Chris@0 26 'description' => 'The {languages}.langcode of the item variant.',
Chris@0 27 'default' => '',
Chris@0 28 ],
Chris@0 29 'type' => [
Chris@0 30 'type' => 'varchar_ascii',
Chris@0 31 'length' => 64,
Chris@0 32 'not null' => TRUE,
Chris@0 33 'description' => 'Type of item, e.g. node.',
Chris@0 34 ],
Chris@0 35 'data' => [
Chris@0 36 'type' => 'text',
Chris@0 37 'not null' => TRUE,
Chris@0 38 'size' => 'big',
Chris@0 39 'description' => 'List of space-separated words from the item.',
Chris@0 40 ],
Chris@0 41 'reindex' => [
Chris@0 42 'type' => 'int',
Chris@0 43 'unsigned' => TRUE,
Chris@0 44 'not null' => TRUE,
Chris@0 45 'default' => 0,
Chris@0 46 'description' => 'Set to force node reindexing.',
Chris@0 47 ],
Chris@0 48 ],
Chris@0 49 'primary key' => ['sid', 'langcode', 'type'],
Chris@0 50 ];
Chris@0 51
Chris@0 52 $schema['search_index'] = [
Chris@0 53 'description' => 'Stores the search index, associating words, items and scores.',
Chris@0 54 'fields' => [
Chris@0 55 'word' => [
Chris@0 56 'type' => 'varchar',
Chris@0 57 'length' => 50,
Chris@0 58 'not null' => TRUE,
Chris@0 59 'default' => '',
Chris@0 60 'description' => 'The {search_total}.word that is associated with the search item.',
Chris@0 61 ],
Chris@0 62 'sid' => [
Chris@0 63 'type' => 'int',
Chris@0 64 'unsigned' => TRUE,
Chris@0 65 'not null' => TRUE,
Chris@0 66 'default' => 0,
Chris@0 67 'description' => 'The {search_dataset}.sid of the searchable item to which the word belongs.',
Chris@0 68 ],
Chris@0 69 'langcode' => [
Chris@0 70 'type' => 'varchar_ascii',
Chris@0 71 'length' => '12',
Chris@0 72 'not null' => TRUE,
Chris@0 73 'description' => 'The {languages}.langcode of the item variant.',
Chris@0 74 'default' => '',
Chris@0 75 ],
Chris@0 76 'type' => [
Chris@0 77 'type' => 'varchar_ascii',
Chris@0 78 'length' => 64,
Chris@0 79 'not null' => TRUE,
Chris@0 80 'description' => 'The {search_dataset}.type of the searchable item to which the word belongs.',
Chris@0 81 ],
Chris@0 82 'score' => [
Chris@0 83 'type' => 'float',
Chris@0 84 'not null' => FALSE,
Chris@0 85 'description' => 'The numeric score of the word, higher being more important.',
Chris@0 86 ],
Chris@0 87 ],
Chris@0 88 'indexes' => [
Chris@0 89 'sid_type' => ['sid', 'langcode', 'type'],
Chris@0 90 ],
Chris@0 91 'foreign keys' => [
Chris@0 92 'search_dataset' => [
Chris@0 93 'table' => 'search_dataset',
Chris@0 94 'columns' => [
Chris@0 95 'sid' => 'sid',
Chris@0 96 'langcode' => 'langcode',
Chris@0 97 'type' => 'type',
Chris@0 98 ],
Chris@0 99 ],
Chris@0 100 ],
Chris@0 101 'primary key' => ['word', 'sid', 'langcode', 'type'],
Chris@0 102 ];
Chris@0 103
Chris@0 104 $schema['search_total'] = [
Chris@0 105 'description' => 'Stores search totals for words.',
Chris@0 106 'fields' => [
Chris@0 107 'word' => [
Chris@0 108 'description' => 'Primary Key: Unique word in the search index.',
Chris@0 109 'type' => 'varchar',
Chris@0 110 'length' => 50,
Chris@0 111 'not null' => TRUE,
Chris@0 112 'default' => '',
Chris@0 113 ],
Chris@0 114 'count' => [
Chris@0 115 'description' => "The count of the word in the index using Zipf's law to equalize the probability distribution.",
Chris@0 116 'type' => 'float',
Chris@0 117 'not null' => FALSE,
Chris@0 118 ],
Chris@0 119 ],
Chris@0 120 'primary key' => ['word'],
Chris@0 121 ];
Chris@0 122
Chris@0 123 return $schema;
Chris@0 124 }
Chris@0 125
Chris@0 126 /**
Chris@0 127 * Implements hook_requirements().
Chris@0 128 *
Chris@0 129 * For the Status Report, return information about search index status.
Chris@0 130 */
Chris@0 131 function search_requirements($phase) {
Chris@0 132 $requirements = [];
Chris@0 133
Chris@0 134 if ($phase == 'runtime') {
Chris@0 135 $remaining = 0;
Chris@0 136 $total = 0;
Chris@0 137 $search_page_repository = \Drupal::service('search.search_page_repository');
Chris@0 138 foreach ($search_page_repository->getIndexableSearchPages() as $entity) {
Chris@0 139 $status = $entity->getPlugin()->indexStatus();
Chris@0 140 $remaining += $status['remaining'];
Chris@0 141 $total += $status['total'];
Chris@0 142 }
Chris@0 143
Chris@0 144 $done = $total - $remaining;
Chris@0 145 // Use floor() to calculate the percentage, so if it is not quite 100%, it
Chris@0 146 // will show as 99%, to indicate "almost done".
Chris@0 147 $percent = ($total > 0 ? floor(100 * $done / $total) : 100);
Chris@0 148 $requirements['search_status'] = [
Chris@0 149 'title' => t('Search index progress'),
Chris@0 150 'value' => t('@percent% (@remaining remaining)', ['@percent' => $percent, '@remaining' => $remaining]),
Chris@0 151 'severity' => REQUIREMENT_INFO,
Chris@0 152 ];
Chris@0 153 }
Chris@0 154
Chris@0 155 return $requirements;
Chris@0 156 }