You are here

function _recommender_generic_top in Recommender API 7.3

Same name and namespace in other branches
  1. 6.3 recommender.module \_recommender_generic_top()
  2. 7.4 recommender.module \_recommender_generic_top()
2 calls to _recommender_generic_top()
recommender_top_prediction in ./recommender.module
Return a list of items that are top prediction for $id
recommender_top_similarity in ./recommender.module
Return a list of items that are top similar with $id

File

./recommender.module, line 119
Providing generic recommender system algorithms.

Code

function _recommender_generic_top($app_name, $id, $top_n, $table, $test_func = NULL) {
  $app_id = recommender_app_load($app_name, TRUE);
  $list = array();
  $result = db_query_range("SELECT target_eid id, score FROM {$table} WHERE app_id=:app_id AND source_eid=:entity_id\n    ORDER BY score DESC, updated DESC, target_eid ASC", 0, TOP_N_LIMIT, array(
    ':app_id' => $app_id,
    ':entity_id' => $id,
  ));
  while (($item = $result
    ->fetchAssoc()) && count($list) < $top_n) {
    if ($test_func === NULL || call_user_func($test_func, $item)) {
      $list[] = $item;
    }
  }
  return $list;
}