home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (search.install)

This example Drupal source code file (search.install) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

array, description, item, node, not, null, of, sid, the, to, true, type, word

The search.install Drupal example source code

<?php
// $Id: search.install,v 1.29 2010/08/22 13:55:53 dries Exp $

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

/**
 * Implements hook_uninstall().
 */
function search_uninstall() {
  variable_del('minimum_word_size');
  variable_del('overlap_cjk');
  variable_del('search_cron_limit');
}

/**
 * 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.',
      ),
      'type' => array(
        'type' => 'varchar',
        'length' => 16,
        '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', '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.',
      ),
      'type' => array(
        'type' => 'varchar',
        'length' => 16,
        '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', 'type'),
    ),
    'foreign keys' => array(
      'search_dataset' => array(
        'table' => 'search_dataset',
        'columns' => array(
          'sid' => 'sid',
          'type' => 'type',
        ),
      ),
    ),
    'primary key' => array('word', 'sid', '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'),
  );

  $schema['search_node_links'] = array(
    'description' => 'Stores items (like nodes) that link to other nodes, used to improve search scores for nodes that are frequently linked to.',
    'fields' => array(
      'sid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'The {search_dataset}.sid of the searchable item containing the link to the node.',
      ),
      'type' => array(
        'type' => 'varchar',
        'length' => 16,
        'not null' => TRUE,
        'default' => '',
        'description' => 'The {search_dataset}.type of the searchable item containing the link to the node.',
      ),
      'nid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'The {node}.nid that this item links to.',
      ),
      'caption' => array(
        'type' => 'text',
        'size' => 'big',
        'not null' => FALSE,
        'description' => 'The text used to link to the {node}.nid.',
      ),
    ),
    'primary key' => array('sid', 'type', 'nid'),
    'indexes' => array(
      'nid' => array('nid'),
    ),
  );

  return $schema;
}

/**
 * Replace unique keys in 'search_dataset' and 'search_index' by primary keys.
 */
function search_update_7000() {
  db_drop_unique_key('search_dataset', 'sid_type');
  $dataset_type_spec = array(
    'type' => 'varchar',
    'length' => 16,
    'not null' => TRUE,
    'description' => 'Type of item, e.g. node.',
  );
  db_change_field('search_dataset', 'type', 'type', $dataset_type_spec);
  db_add_primary_key('search_dataset', array('sid', 'type'));

  db_drop_index('search_index', 'word');
  db_drop_unique_key('search_index', 'word_sid_type');
  $index_type_spec = array(
    'type' => 'varchar',
    'length' => 16,
    'not null' => TRUE,
    'description' => 'The {search_dataset}.type of the searchable item to which the word belongs.',
  );
  db_change_field('search_index', 'type', 'type', $index_type_spec);
  db_add_primary_key('search_index', array('word', 'sid', 'type'));
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal search.install source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.