function recommender_schema in Recommender API 7.5
Same name and namespace in other branches
- 5 recommender.install \recommender_schema()
- 6.3 recommender.install \recommender_schema()
- 6 recommender.install \recommender_schema()
- 6.2 recommender.install \recommender_schema()
- 7.6 recommender.install \recommender_schema()
- 7.3 recommender.install \recommender_schema()
- 7.4 recommender.install \recommender_schema()
Implements hook_schema().
Note: One big difference compared to previous release is to remove the {recommender_app} table and simply uses a varchar field 'recommender' to distinguish between different applications. Such a design violates database normal forms, and it might have negative effects on performance. But it does simplifies programing logic. Let's see if it needs change in the feature.
File
- ./
recommender.install, line 14 - Installation file for the Recommender API module. Note: Not compatible with 6.x releases. Please uninstall 6.x releases before installing the D7 release.
Code
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 the same 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,
),
'recommender' => array(
'description' => 'This field distinguishes different recommender applications.',
'type' => 'varchar',
'length' => 20,
'not null' => TRUE,
),
'source_id' => array(
'description' => 'The first source entity_id. This is usually user id.',
'type' => 'int',
'size' => 'normal',
'unsigned' => TRUE,
'not null' => TRUE,
),
'target_id' => array(
'description' => 'The target entity_id. This is usually item 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 source prefers target more.',
),
'updated' => array(
'description' => 'The Unix timestamp this preference is last changed',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array(
'id',
),
// note that this is not unique indexes.
'indexes' => array(
'recommender' => array(
'recommender',
),
'index_key' => array(
'recommender',
'source_id',
'target_id',
),
),
),
// table to save similarity scores
'recommender_similarity' => array(
'description' => 'This is the main table to save similarity data. The structure is the same to prediction table, but stores different 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,
),
'recommender' => array(
'description' => 'This field distinguishes different recommender applications.',
'type' => 'varchar',
'length' => 20,
'not null' => TRUE,
),
'source_id' => array(
'description' => 'The first source entity_id. The type is the same to the target entity',
'type' => 'int',
'size' => 'normal',
'unsigned' => TRUE,
'not null' => TRUE,
),
'target_id' => array(
'description' => 'The target entity_id. The type is the same to the source entity',
'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',
),
// note that this is not unique indexes.
'indexes' => array(
'recommender' => array(
'recommender',
),
'index_key' => array(
'recommender',
'source_id',
'target_id',
),
),
),
// table to save predictions
'recommender_prediction' => array(
'description' => 'This is the main table to save prediction data. The structure is the same to similarity table, but here source and target are different type of entities',
'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,
),
'recommender' => array(
'description' => 'This field distinguishes different recommender applications.',
'type' => 'varchar',
'length' => 20,
'not null' => TRUE,
),
'source_id' => array(
'description' => 'The entity_id for which the prediction is generated. This is usually user id',
'type' => 'int',
'size' => 'normal',
'unsigned' => TRUE,
'not null' => TRUE,
),
'target_id' => array(
'description' => 'The entity_id of the target prediction. This is usually item 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 source prefers target more.',
),
'updated' => array(
'description' => 'The Unix timestamp this prediction is last changed',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array(
'id',
),
// note that this is not unique indexes.
'indexes' => array(
'recommender' => array(
'recommender',
),
'index_key' => array(
'recommender',
'source_id',
'target_id',
),
),
),
'recommender_preference_staging' => array(
'description' => 'This table stages user-item preference data if it is from a SQL query. Should get purged before app running',
'fields' => array(
'source_id' => array(
'description' => 'The entity_id of the owner of the preference. This is usually user id',
'type' => 'int',
'size' => 'normal',
'unsigned' => TRUE,
'not null' => TRUE,
),
'target_id' => array(
'description' => 'The entity_id of the target of the preference. This is usually item 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 source prefers target more.',
),
'updated' => array(
'description' => 'The Unix timestamp this preference is last changed',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array(
'source_id',
'target_id',
),
),
);
return $schema;
}