From b2a6d5cfa4ef4c67851310369ac33ef58d307a97 Mon Sep 17 00:00:00 2001 From: iglocska Date: Sun, 10 Feb 2019 22:20:54 +0100 Subject: [PATCH] chg: [Tag search API] now also accepts synonyms as input --- app/Controller/TagsController.php | 32 +++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/app/Controller/TagsController.php b/app/Controller/TagsController.php index 2a677e614..759eda1c0 100644 --- a/app/Controller/TagsController.php +++ b/app/Controller/TagsController.php @@ -1045,21 +1045,33 @@ class TagsController extends AppController } else if (!empty($this->request->data)) { $tag = $this->request->data; } - if (is_array($tag)) { - foreach ($tag as $k => $t) { - $tag[$k] = strtolower($t); - } - } else { - $tag = strtolower($tag); + if (!is_array($tag)) { + $tag = array($tag); + } + foreach ($tag as $k => $t) { + $tag[$k] = strtolower($t); + } + $this->loadModel('GalaxyCluster'); + $conditions = array('GalaxyElement.key' => 'synonyms', 'OR' => array()); + foreach ($tag as $k => $t) { + $conditions['OR'][] = array('LOWER(GalaxyElement.value) LIKE' => $t); + } + $elements = $this->GalaxyCluster->GalaxyElement->find('all', array( + 'recursive' => -1, + 'conditions' => $conditions, + 'contain' => array('GalaxyCluster.tag_name') + )); + foreach ($elements as $element) { + $tag[] = strtolower($element['GalaxyCluster']['tag_name']); + } + $conditions = array(); + foreach ($tag as $k => $t) { + $conditions['OR'][] = array('LOWER(Tag.name) LIKE' => $t); } - $conditions = array( - 'LOWER(Tag.name) LIKE ' => $tag - ); $tags = $this->Tag->find('all', array( 'conditions' => $conditions, 'recursive' => -1 )); - $this->loadModel('GalaxyCluster'); $this->loadModel('Taxonomy'); foreach ($tags as $k => $t) { $taxonomy = $this->Taxonomy->getTaxonomyForTag($t['Tag']['name'], true);