You are here

search.install in Zircon Profile 8.0

Same filename and directory in other branches
  1. 8 core/modules/search/search.install

Install, update, and uninstall functions for the Search module.

File

core/modules/search/search.install
View source
<?php

/**
 * @file
 * Install, update, and uninstall functions for the Search module.
 */

/**
 * Implements hook_schema().
 */
function search_schema() {
  $schema['search_dataset'] = array(
    'description' => 'Stores items that will be searched.',
    'fields' => array(
      'sid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Search item ID, e.g. node ID for nodes.',
      ),
      'langcode' => array(
        'type' => 'varchar_ascii',
        'length' => '12',
        'not null' => TRUE,
        'description' => 'The {languages}.langcode of the item variant.',
        'default' => '',
      ),
      'type' => array(
        'type' => 'varchar_ascii',
        'length' => 64,
        'not null' => TRUE,
        'description' => 'Type of item, e.g. node.',
      ),
      'data' => array(
        'type' => 'text',
        'not null' => TRUE,
        'size' => 'big',
        'description' => 'List of space-separated words from the item.',
      ),
      'reindex' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Set to force node reindexing.',
      ),
    ),
    'primary key' => array(
      'sid',
      'langcode',
      'type',
    ),
  );
  $schema['search_index'] = array(
    'description' => 'Stores the search index, associating words, items and scores.',
    'fields' => array(
      'word' => array(
        'type' => 'varchar',
        'length' => 50,
        'not null' => TRUE,
        'default' => '',
        'description' => 'The {search_total}.word that is associated with the search item.',
      ),
      'sid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'The {search_dataset}.sid of the searchable item to which the word belongs.',
      ),
      'langcode' => array(
        'type' => 'varchar_ascii',
        'length' => '12',
        'not null' => TRUE,
        'description' => 'The {languages}.langcode of the item variant.',
        'default' => '',
      ),
      'type' => array(
        'type' => 'varchar_ascii',
        'length' => 64,
        'not null' => TRUE,
        'description' => 'The {search_dataset}.type of the searchable item to which the word belongs.',
      ),
      'score' => array(
        'type' => 'float',
        'not null' => FALSE,
        'description' => 'The numeric score of the word, higher being more important.',
      ),
    ),
    'indexes' => array(
      'sid_type' => array(
        'sid',
        'langcode',
        'type',
      ),
    ),
    'foreign keys' => array(
      'search_dataset' => array(
        'table' => 'search_dataset',
        'columns' => array(
          'sid' => 'sid',
          'langcode' => 'langcode',
          'type' => 'type',
        ),
      ),
    ),
    'primary key' => array(
      'word',
      'sid',
      'langcode',
      'type',
    ),
  );
  $schema['search_total'] = array(
    'description' => 'Stores search totals for words.',
    'fields' => array(
      'word' => array(
        'description' => 'Primary Key: Unique word in the search index.',
        'type' => 'varchar',
        'length' => 50,
        'not null' => TRUE,
        'default' => '',
      ),
      'count' => array(
        'description' => "The count of the word in the index using Zipf's law to equalize the probability distribution.",
        'type' => 'float',
        'not null' => FALSE,
      ),
    ),
    'primary key' => array(
      'word',
    ),
  );
  return $schema;
}

/**
 * Implements hook_requirements().
 *
 * For the Status Report, return information about search index status.
 */
function search_requirements($phase) {
  $requirements = array();
  if ($phase == 'runtime') {
    $remaining = 0;
    $total = 0;
    $search_page_repository = \Drupal::service('search.search_page_repository');
    foreach ($search_page_repository
      ->getIndexableSearchPages() as $entity) {
      $status = $entity
        ->getPlugin()
        ->indexStatus();
      $remaining += $status['remaining'];
      $total += $status['total'];
    }
    $done = $total - $remaining;

    // Use floor() to calculate the percentage, so if it is not quite 100%, it
    // will show as 99%, to indicate "almost done".
    $percent = $total > 0 ? floor(100 * $done / $total) : 100;
    $requirements['search_status'] = array(
      'title' => t('Search index progress'),
      'value' => t('@percent% (@remaining remaining)', array(
        '@percent' => $percent,
        '@remaining' => $remaining,
      )),
      'severity' => REQUIREMENT_INFO,
    );
  }
  return $requirements;
}

Functions

Namesort descending Description
search_requirements Implements hook_requirements().
search_schema Implements hook_schema().