chg: [Tag search API] now also accepts synonyms as input

pull/4138/head
iglocska 2019-02-10 22:20:54 +01:00
parent 09cbbe3b93
commit b2a6d5cfa4
1 changed files with 22 additions and 10 deletions

View File

@ -1045,21 +1045,33 @@ class TagsController extends AppController
} else if (!empty($this->request->data)) { } else if (!empty($this->request->data)) {
$tag = $this->request->data; $tag = $this->request->data;
} }
if (is_array($tag)) { if (!is_array($tag)) {
foreach ($tag as $k => $t) { $tag = array($tag);
$tag[$k] = strtolower($t); }
} foreach ($tag as $k => $t) {
} else { $tag[$k] = strtolower($t);
$tag = strtolower($tag); }
$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( $tags = $this->Tag->find('all', array(
'conditions' => $conditions, 'conditions' => $conditions,
'recursive' => -1 'recursive' => -1
)); ));
$this->loadModel('GalaxyCluster');
$this->loadModel('Taxonomy'); $this->loadModel('Taxonomy');
foreach ($tags as $k => $t) { foreach ($tags as $k => $t) {
$taxonomy = $this->Taxonomy->getTaxonomyForTag($t['Tag']['name'], true); $taxonomy = $this->Taxonomy->getTaxonomyForTag($t['Tag']['name'], true);