You are here

recommender.install in Recommender API 7.6

Installation file for the Recommender API module.

File

recommender.install
View source
<?php

/**
 * @file
 * Installation file for the Recommender API module.
 */

/**
 * Implements hook_schema().
 * Helper modules should use drupal_get_unprocessed_schema() to create tables for their own.
 */
function recommender_schema() {
  $schema = array(
    // table to save preference scores
    'recommender_preference' => array(
      'description' => 'This is the main table to save preference data. The structure is similar to prediction/similarity table.',
      'fields' => array(
        // this id might be redundant.
        'id' => array(
          'description' => 'Unique index for each preference data',
          'type' => 'serial',
          'size' => 'normal',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ),
        'uid' => array(
          'description' => 'User ID',
          'type' => 'int',
          'size' => 'normal',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ),
        'eid' => array(
          'description' => 'Entity ID',
          'type' => 'int',
          'size' => 'normal',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ),
        'score' => array(
          'type' => 'float',
          'size' => 'normal',
          'not null' => FALSE,
          'description' => 'The preference score. Higher score means the user prefers the item more.',
        ),
        'updated' => array(
          'description' => 'The Unix timestamp a record is last changed',
          'type' => 'int',
          'not null' => TRUE,
          'default' => 0,
        ),
      ),
      'primary key' => array(
        'id',
      ),
      //      'foreign keys' => array(
      //        'uid' => array(
      //          'table' => 'users',
      //          'columns' => array('uid' => 'uid'),
      //        ),
      //      ),
      'indexes' => array(
        'uid_eid' => array(
          'uid',
          'eid',
        ),
      ),
    ),
    // table to save user similarity scores
    'recommender_user_similarity' => array(
      'description' => 'This is the main table to save user similarity data.',
      'fields' => array(
        // this id might be redundant.
        'id' => array(
          'description' => 'Unique index for each similarity pair',
          'type' => 'serial',
          'size' => 'normal',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ),
        'uid1' => array(
          'description' => 'The first user ID',
          'type' => 'int',
          'size' => 'normal',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ),
        'uid2' => array(
          'description' => 'The second user ID',
          'type' => 'int',
          'size' => 'normal',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ),
        'score' => array(
          'type' => 'float',
          'size' => 'normal',
          'not null' => FALSE,
          'description' => 'Similarity score. The bigger, the more similar',
        ),
        'updated' => array(
          'description' => 'The Unix timestamp this similarity is last changed',
          'type' => 'int',
          'not null' => TRUE,
          'default' => 0,
        ),
      ),
      'primary key' => array(
        'id',
      ),
      //      'foreign keys' => array(
      //        'uid1' => array(
      //          'table' => 'users',
      //          'columns' => array('uid1' => 'uid'),
      //        ),
      //        'uid2' => array(
      //          'table' => 'users',
      //          'columns' => array('uid1' => 'uid'),
      //        ),
      //      ),
      'indexes' => array(
        'uid1_uid2' => array(
          'uid1',
          'uid2',
        ),
      ),
    ),
    // table to save item similarity scores
    'recommender_item_similarity' => array(
      'description' => 'This is the main table to save item similarity data.',
      'fields' => array(
        // this id might be redundant.
        'id' => array(
          'description' => 'Unique index for each similarity pair',
          'type' => 'serial',
          'size' => 'normal',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ),
        'eid1' => array(
          'description' => 'The first entity ID',
          'type' => 'int',
          'size' => 'normal',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ),
        'eid2' => array(
          'description' => 'The second entity ID',
          'type' => 'int',
          'size' => 'normal',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ),
        'score' => array(
          'type' => 'float',
          'size' => 'normal',
          'not null' => FALSE,
          'description' => 'Similarity score. The bigger, the more similar',
        ),
        'updated' => array(
          'description' => 'The Unix timestamp this similarity is last changed',
          'type' => 'int',
          'not null' => TRUE,
          'default' => 0,
        ),
      ),
      'primary key' => array(
        'id',
      ),
      'indexes' => array(
        'eid1_eid2' => array(
          'eid1',
          'eid2',
        ),
      ),
    ),
    // table to save prediction data
    'recommender_prediction' => array(
      'description' => 'This is the main table to save prediction data.',
      'fields' => array(
        // this id might be redundant.
        'id' => array(
          'description' => 'Unique index for each prediction link',
          'type' => 'serial',
          'size' => 'normal',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ),
        'uid' => array(
          'description' => 'User id',
          'type' => 'int',
          'size' => 'normal',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ),
        'eid' => array(
          'description' => 'Entity ID',
          'type' => 'int',
          'size' => 'normal',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ),
        'score' => array(
          'type' => 'float',
          'size' => 'normal',
          'not null' => FALSE,
          'description' => 'The prediction score. Higher score means the user prefers the item more.',
        ),
        'updated' => array(
          'description' => 'The Unix timestamp this prediction is last changed',
          'type' => 'int',
          'not null' => TRUE,
          'default' => 0,
        ),
      ),
      'primary key' => array(
        'id',
      ),
      //      'foreign keys' => array(
      //        'uid' => array(
      //          'table' => 'users',
      //          'columns' => array('uid' => 'uid'),
      //        ),
      //      ),
      'indexes' => array(
        'uid_eid' => array(
          'uid',
          'eid',
        ),
      ),
    ),
  );
  return $schema;
}

/**
 * Implements hook_install().
 */
function recommender_install() {
  $app = computing_application_create_entity(array(
    'application' => 'recommender',
    'label' => 'Recommender Application',
    'description' => 'Application for Recommender API.',
  ));
  $app
    ->save();
}

/**
 * Implements hook_uninstall().
 */
function recommender_uninstall() {
  $app = computing_get_applications('recommender');
  entity_delete('computing_application', $app->id);
}

Functions

Namesort descending Description
recommender_install Implements hook_install().
recommender_schema Implements hook_schema(). Helper modules should use drupal_get_unprocessed_schema() to create tables for their own.
recommender_uninstall Implements hook_uninstall().