You are here

function recommender_process_record in Recommender API 7.6

This function process the command, and saves result back to $record. Will not save record.

Parameters

$record:

Return value

mixed

2 calls to recommender_process_record()
drush_recommender_run in ./recommender.drush.inc
recommender_run in ./recommender.module

File

./recommender.module, line 304

Code

function recommender_process_record($record) {
  $mapping = array(
    'user2user' => 'UserBasedRecommender',
    'user2user_boolean' => 'UserBasedBooleanRecommender',
    'item2item' => 'ItemBasedRecommender',
    'item2item_boolean' => 'ItemBasedBooleanRecommender',
  );
  if (!array_key_exists($record->command, $mapping)) {
    $record->status = 'FLD';
    $record->message = 'Cannot identify recommender command';
    $record->output = NULL;
    return;
  }
  $recommender_class = $mapping[$record->command];
  $recommender = new $recommender_class();

  // compute, could be time-consuming.
  try {
    $recommender
      ->initialize($record->input);
    $recommender
      ->execute();
    $result = $recommender
      ->finalize();
  } catch (Exception $e) {
    $record->status = 'FLD';
    $record->message = 'Unexpected exception caught: ' . $e
      ->getMessage();
    $record->output = NULL;
    return;
  }
  $record->status = 'SCF';
  $record->message = 'Successfully computed recommendations.';
  $record->output = $result;
}