From 20fea9dce1df98a819bc8162a653b75ca06fe21f Mon Sep 17 00:00:00 2001 From: bach Date: Wed, 27 Oct 2021 15:51:14 +0200 Subject: [PATCH] better search with filters --- .../materio_sapi/src/Controller/Base.php | 55 +++++++++++-------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/web/modules/custom/materio_sapi/src/Controller/Base.php b/web/modules/custom/materio_sapi/src/Controller/Base.php index eee3ab4..ca075b4 100644 --- a/web/modules/custom/materio_sapi/src/Controller/Base.php +++ b/web/modules/custom/materio_sapi/src/Controller/Base.php @@ -73,41 +73,40 @@ class Base extends ControllerBase { // $this->or_query->setOption('termid', $this->term); } - $fulltextFields = []; - if ($this->filters) { // FILTERS $filters_conditions = $this->and_query->createConditionGroup('AND'); foreach ($this->filters as $filter) { $filter = (int) $filter; - foreach (['tag_tid', 'thesaurus_tid'] as $field) { + foreach (['thesaurus_tid'] as $field) { // 'tag_tid', $filters_conditions->addCondition($field, $filter); } } $this->and_query->addConditionGroup($filters_conditions); - }else{ - // Recherche uniquement sur les champ thésaurus et tag - $fulltextFields += [ - 'thesaurus_name_0', - 'thesaurus_synonyms_0', - 'thesaurus_name_1', - 'thesaurus_synonyms_1', - 'thesaurus_name_2', - 'thesaurus_synonyms_2', - 'thesaurus_name_3', - 'thesaurus_synonyms_3', - 'thesaurus_name_4', - 'thesaurus_synonyms_4', - 'thesaurus_name', - 'thesaurus_synonyms', - 'tag_name', - 'tag_synonyms' - ]; } - + // else{ + $fulltextFields = []; + // Recherche uniquement sur les champ thésaurus et tag + $fulltextFields += [ + 'thesaurus_name_0', + 'thesaurus_synonyms_0', + 'thesaurus_name_1', + 'thesaurus_synonyms_1', + 'thesaurus_name_2', + 'thesaurus_synonyms_2', + 'thesaurus_name_3', + 'thesaurus_synonyms_3', + 'thesaurus_name_4', + 'thesaurus_synonyms_4', + 'thesaurus_name', + 'thesaurus_synonyms', + 'tag_name', + 'tag_synonyms' + ]; if(count($fulltextFields)){ $this->and_query->setFulltextFields($fulltextFields); } + // } // Restrict the search to specific languages. $this->and_query->setLanguages([$lang]); @@ -171,6 +170,18 @@ class Base extends ControllerBase { $this->or_query->addConditionGroup($ref_conditions); } + if ($this->filters) { + // FILTERS + $or_filters_conditions = $this->or_query->createConditionGroup('OR'); + foreach ($this->filters as $filter) { + $filter = (int) $filter; + foreach (['thesaurus_tid'] as $field) { // 'tag_tid', + $or_filters_conditions->addCondition($field, $filter); + } + } + $this->or_query->addConditionGroup($or_filters_conditions); + } + // Restrict the search to specific languages. $this->or_query->setLanguages([$lang]);