FIX getTermWeight

This commit is contained in:
root 2019-08-04 14:47:21 +02:00
parent da637c83de
commit e4ffb99b54

View file

@ -105,11 +105,11 @@ class RelatedRorController extends ControllerBase {
} }
private function getTermWeight(int $termid): int { private function getTermWeight(int $termid): int {
$term = \Drupal\node\Entity\Term::load($termid); $term = \Drupal\taxonomy\Entity\Term::load($termid);
$query = \Drupal::database()->select('taxonomy_index', 'ti'); $query = \Drupal::database()->select('taxonomy_index', 'ti');
$query->fields('ti', ['nid']); $query->fields('ti', ['nid']);
$query->condition('ti.tid', $term_id); $query->condition('ti.tid', $termid);
$cnt = $query->execute()->rowCount(); $cnt = $query->countQuery()->execute()->fetchField();
if($cnt < 100) { if($cnt < 100) {
return 2; return 2;
} }
@ -120,8 +120,8 @@ class RelatedRorController extends ControllerBase {
$orig_tags = array_map(function($t) { return $t['target_id']; }, $orig['field_tags']); $orig_tags = array_map(function($t) { return $t['target_id']; }, $orig['field_tags']);
$other_tags = array_map(function($t) { return $t['target_id']; }, $other['field_tags']); $other_tags = array_map(function($t) { return $t['target_id']; }, $other['field_tags']);
$both = array_intersect($orig_tags, $other_tags); $both = array_intersect($orig_tags, $other_tags);
$weighted = array_map($this->getTermWeight, $both); $weighted = array_map([$this, 'getTermWeight'], $both);
return array_sum($weighted); return array_sum($weighted) || 0;
} }
private function cachedJsonResp(array $data): Response { private function cachedJsonResp(array $data): Response {