class CooccurrenceRecommender in Recommender API 6.2
The simple co-occurrence algorithm
Hierarchy
- class \Recommender
- class \CooccurrenceRecommender
Expanded class hierarchy of CooccurrenceRecommender
File
- ./
Recommender.php, line 651
View source
class CooccurrenceRecommender extends Recommender {
// allow $fieldWeight to be NULL
function __construct($appName, $tableName, $fieldMouse, $fieldCheese, $fieldWeight = NULL, $options = array()) {
parent::__construct($appName, $tableName, $fieldMouse, $fieldCheese, $fieldWeight, $options);
}
function computeSimilarity() {
$this
->prepareData('database');
$this
->computeSimilarityDatabase();
}
// Note: removed the $incremental==update mode [#480300]
// To see the removed code, go to branch DRUPAL-6--1-1
protected function computeSimilarityDatabase() {
watchdog("recommender", "Computing similarity in database. Might take a long time. Please be patient.");
if ($this->fieldWeight === NULL) {
$count = "COUNT(*)";
// if no $fieldWeight is specified, just count the occurrences.
}
else {
// otherwise, use the weight.
$count = "SUM((n1.{$this->fieldWeight}+n2.{$this->fieldWeight})/2)";
}
$sql = "INSERT INTO {recommender_similarity}(app_id, mouse1_id, mouse2_id, similarity, created)\n SELECT {$this->appId}, n1.{$this->fieldMouse}, n2.{$this->fieldMouse}, {$count}, {$this->created}\n FROM {{$this->tableName}} n1 INNER JOIN {{$this->tableName}} n2 ON n1.{$this->fieldCheese}=n2.{$this->fieldCheese}\n GROUP BY n1.{$this->fieldMouse}, n2.{$this->fieldMouse}";
update_sql($sql);
$this
->purgeOutdatedRecords('similarity');
}
}