better search with filters

This commit is contained in:
Bachir Soussi Chiadmi 2021-10-27 15:51:14 +02:00
parent c5fe8c0c92
commit 20fea9dce1
1 changed files with 33 additions and 22 deletions

View File

@ -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]);