From e4ffb99b544aa4a85e3fe3c94508974a3e4c1dfe Mon Sep 17 00:00:00 2001 From: root Date: Sun, 4 Aug 2019 14:47:21 +0200 Subject: [PATCH] FIX getTermWeight --- src/Controller/RelatedRorController.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Controller/RelatedRorController.php b/src/Controller/RelatedRorController.php index 3ca7ca2..a67d39e 100644 --- a/src/Controller/RelatedRorController.php +++ b/src/Controller/RelatedRorController.php @@ -105,11 +105,11 @@ class RelatedRorController extends ControllerBase { } 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->fields('ti', ['nid']); - $query->condition('ti.tid', $term_id); - $cnt = $query->execute()->rowCount(); + $query->condition('ti.tid', $termid); + $cnt = $query->countQuery()->execute()->fetchField(); if($cnt < 100) { return 2; } @@ -120,8 +120,8 @@ class RelatedRorController extends ControllerBase { $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']); $both = array_intersect($orig_tags, $other_tags); - $weighted = array_map($this->getTermWeight, $both); - return array_sum($weighted); + $weighted = array_map([$this, 'getTermWeight'], $both); + return array_sum($weighted) || 0; } private function cachedJsonResp(array $data): Response {