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