diff --git a/VERSIONS_HOTLINE/28087 b/VERSIONS_HOTLINE/28087 new file mode 100644 index 0000000000000000000000000000000000000000..42c9a123a2c742056726ba1ece60c72f4869fa3b --- /dev/null +++ b/VERSIONS_HOTLINE/28087 @@ -0,0 +1 @@ +- ticket #28087 : sur une recherche avancée avec "ou" (ex titres=pomme ou auteur=rowling), la sélection des facettes ne fonctionnait plus sur le résultat \ No newline at end of file diff --git a/library/Class/MoteurRecherche.php b/library/Class/MoteurRecherche.php index d946e05040c5bf03fda6edc1aa8965928fcad7c4..96f82749c336d38e5d3e24ea4084d8618fcb6da1 100644 --- a/library/Class/MoteurRecherche.php +++ b/library/Class/MoteurRecherche.php @@ -29,6 +29,7 @@ class Class_MoteurRecherche { $rubriques, $_domain_conditions = null, $conditions = '', + $_with_operator_conditions = [], $_or_conditions = '', $_filter_domain_conditions = ''; @@ -272,15 +273,13 @@ class Class_MoteurRecherche { if (!$operateur) $operateur = 'and'; - if($this->conditions) - $this->conditions .= ' ' . $operateur . ' '; - elseif(stripos($operateur, 'NOT')) - $this->conditions .= 'not '; - // Type de recherche - $this->conditions .= ($type_recherche == 'fulltext') + $condition = ($type_recherche == 'fulltext') ? "MATCH(".$name.") AGAINST('".$recherche."' IN BOOLEAN MODE)" : $name . " like '" . $recherche . "%'"; + + $this->_with_operator_conditions []= ['operator' => strtolower($operateur), + 'condition' => $condition]; } @@ -357,6 +356,7 @@ class Class_MoteurRecherche { public function visitSearchSettings($criteres_recherche) { $this->criteres_recherche = $criteres_recherche; $this->conditions = ''; + $this->_with_operator_conditions = []; $this->all_facettes = ''; $this->select_notices = 'id_notice from notices'; $this->nb_mots = 0; @@ -369,7 +369,24 @@ class Class_MoteurRecherche { } + protected function injectWithOperatorConditions() { + if (!$this->_with_operator_conditions) + return $this; + + $first_condition = array_shift($this->_with_operator_conditions); + $operators_conditions = '(' . (strpos($first_condition['operator'], 'not') ? 'not ' : '') . $first_condition['condition']; + foreach ($this->_with_operator_conditions as $condition) + $operators_conditions .= ' ' . $condition['operator'] . ' ' . $condition['condition']; + $operators_conditions .= ')'; + + $this->conditions = implode(' and ', array_filter([$this->conditions, $operators_conditions])); + return $this; + } + + public function buildWherePartQuery() { + $this->injectWithOperatorConditions(); + if(!is_null($this->_domain_conditions)) { $this->setCondition($this->_domain_conditions); return self::getConditionsForRequest($this->conditions, $this->_or_conditions, $this->_filter_domain_conditions); diff --git a/tests/library/Class/MoteurRechercheTest.php b/tests/library/Class/MoteurRechercheTest.php index ab5a6c4669ea6e6539126c820b1d071a3059c60a..b90c21f33197c96992ae549b9766ed32c9fcd066 100644 --- a/tests/library/Class/MoteurRechercheTest.php +++ b/tests/library/Class/MoteurRechercheTest.php @@ -113,20 +113,20 @@ class MoteurRechercheAvanceeTest extends MoteurRechercheTestCase { 'type_recherche' => 'fulltext', 'pertinence' => false, 'tri' => 'alpha_auteur'] , - 'req_notices' => $this->listSqlWith("MATCH(auteurs) AGAINST('+(FOUCAULT FOUCAULTS FOUKOLT)' IN BOOLEAN MODE)", + 'req_notices' => $this->listSqlWith("(MATCH(auteurs) AGAINST('+(FOUCAULT FOUCAULTS FOUKOLT)' IN BOOLEAN MODE))", 'alpha_auteur'), - 'req_comptage' => $this->countSqlWith("MATCH(auteurs) AGAINST('+(FOUCAULT FOUCAULTS FOUKOLT)' IN BOOLEAN MODE)"), - 'req_facettes' => $this->facetSqlWith("MATCH(auteurs) AGAINST('+(FOUCAULT FOUCAULTS FOUKOLT)' IN BOOLEAN MODE)")], + 'req_comptage' => $this->countSqlWith("(MATCH(auteurs) AGAINST('+(FOUCAULT FOUCAULTS FOUKOLT)' IN BOOLEAN MODE))"), + 'req_facettes' => $this->facetSqlWith("(MATCH(auteurs) AGAINST('+(FOUCAULT FOUCAULTS FOUKOLT)' IN BOOLEAN MODE))")], [['rech_auteurs' => 'Bourdieu', 'operateur_auteurs' => 'and', 'type_recherche' => 'commence', 'pertinence' => true, 'tri' => 'alpha_titre'] , - 'req_notices' => $this->listSqlWith("auteurs like 'BOURDIEU%'", + 'req_notices' => $this->listSqlWith("(auteurs like 'BOURDIEU%')", "alpha_titre"), - 'req_comptage' => $this->countSqlWith("auteurs like 'BOURDIEU%'"), - 'req_facettes' => $this->facetSqlWith("auteurs like 'BOURDIEU%'")], + 'req_comptage' => $this->countSqlWith("(auteurs like 'BOURDIEU%')"), + 'req_facettes' => $this->facetSqlWith("(auteurs like 'BOURDIEU%')")], [['rech_auteurs' => 'Clastres', 'operateur_auteurs' => 'and', @@ -135,10 +135,10 @@ class MoteurRechercheAvanceeTest extends MoteurRechercheTestCase { 'type_recherche' => 'commence', 'pertinence' => true, 'tri' => 'alpha_titre'] , - 'req_notices' => $this->listSqlWith( "auteurs like 'CLASTRES%' and MATCH(facettes) AGAINST('+YMED1 +(YTUN YTAP)' IN BOOLEAN MODE)", + 'req_notices' => $this->listSqlWith( "(auteurs like 'CLASTRES%') and MATCH(facettes) AGAINST('+YMED1 +(YTUN YTAP)' IN BOOLEAN MODE)", 'alpha_titre'), - 'req_comptage' => $this->countSqlWith("auteurs like 'CLASTRES%' and MATCH(facettes) AGAINST('+YMED1 +(YTUN YTAP)' IN BOOLEAN MODE)"), - 'req_facettes' => $this->facetSqlWith("auteurs like 'CLASTRES%' and MATCH(facettes) AGAINST('+YMED1 +(YTUN YTAP)' IN BOOLEAN MODE)")], + 'req_comptage' => $this->countSqlWith("(auteurs like 'CLASTRES%') and MATCH(facettes) AGAINST('+YMED1 +(YTUN YTAP)' IN BOOLEAN MODE)"), + 'req_facettes' => $this->facetSqlWith("(auteurs like 'CLASTRES%') and MATCH(facettes) AGAINST('+YMED1 +(YTUN YTAP)' IN BOOLEAN MODE)")], [['rech_matieres' => 'Philosophie', 'operateur_matieres' => 'and not', @@ -149,10 +149,10 @@ class MoteurRechercheAvanceeTest extends MoteurRechercheTestCase { 'type_recherche' => 'commence', 'pertinence' => true, 'tri' => 'alpha_titre'] , - 'req_notices' => $this->listSqlWith("not matieres like 'PHILOSOPHIE%' and annee >='1960' and annee <='2013' and date_creation >'".$this->expected_date."' and MATCH(facettes) AGAINST('+T1' IN BOOLEAN MODE)", + 'req_notices' => $this->listSqlWith("annee >='1960' and annee <='2013' and date_creation >'".$this->expected_date."' and (not matieres like 'PHILOSOPHIE%') and MATCH(facettes) AGAINST('+T1' IN BOOLEAN MODE)", "alpha_titre"), - 'req_comptage' => $this->countSqlWith("not matieres like 'PHILOSOPHIE%' and annee >='1960' and annee <='2013' and date_creation >'".$this->expected_date."' and MATCH(facettes) AGAINST('+T1' IN BOOLEAN MODE)"), - 'req_facettes' => $this->facetSqlWith("not matieres like 'PHILOSOPHIE%' and annee >='1960' and annee <='2013' and date_creation >'".$this->expected_date."' and MATCH(facettes) AGAINST('+T1' IN BOOLEAN MODE)")], + 'req_comptage' => $this->countSqlWith("annee >='1960' and annee <='2013' and date_creation >'".$this->expected_date."' and (not matieres like 'PHILOSOPHIE%') and MATCH(facettes) AGAINST('+T1' IN BOOLEAN MODE)"), + 'req_facettes' => $this->facetSqlWith("annee >='1960' and annee <='2013' and date_creation >'".$this->expected_date."' and (not matieres like 'PHILOSOPHIE%') and MATCH(facettes) AGAINST('+T1' IN BOOLEAN MODE)")], [['rech_titres' => 'Les nouveaux chiens de garde', 'operateur_titres' => 'and', @@ -163,10 +163,10 @@ class MoteurRechercheAvanceeTest extends MoteurRechercheTestCase { 'type_recherche' => 'nimportequoi', 'pertinence' => false, 'tri' => 'alpha_titre'] , - 'req_notices' => $this->listSqlWith("MATCH(titres) AGAINST('+(NOUVEAU NOUVEAUX NOUVO) +(CHIEN CHIENS CHIN) +(GARDE GARDES GARD)' IN BOOLEAN MODE) or MATCH(editeur) AGAINST('+(RAISON RAISONS RAISON) +(D00 D00S ) +(AGIR AGIRS AJIR)' IN BOOLEAN MODE) and date_creation >'2012-02-03' and MATCH(facettes) AGAINST('+B4' IN BOOLEAN MODE)", + 'req_notices' => $this->listSqlWith("date_creation >'2012-02-03' and (MATCH(titres) AGAINST('+(NOUVEAU NOUVEAUX NOUVO) +(CHIEN CHIENS CHIN) +(GARDE GARDES GARD)' IN BOOLEAN MODE) or MATCH(editeur) AGAINST('+(RAISON RAISONS RAISON) +(D00 D00S ) +(AGIR AGIRS AJIR)' IN BOOLEAN MODE)) and MATCH(facettes) AGAINST('+B4' IN BOOLEAN MODE)", 'alpha_titre'), - 'req_comptage' => $this->countSqlWith("MATCH(titres) AGAINST('+(NOUVEAU NOUVEAUX NOUVO) +(CHIEN CHIENS CHIN) +(GARDE GARDES GARD)' IN BOOLEAN MODE) or MATCH(editeur) AGAINST('+(RAISON RAISONS RAISON) +(D00 D00S ) +(AGIR AGIRS AJIR)' IN BOOLEAN MODE) and date_creation >'2012-02-03' and MATCH(facettes) AGAINST('+B4' IN BOOLEAN MODE)"), - 'req_facettes' => $this->facetSqlWith("MATCH(titres) AGAINST('+(NOUVEAU NOUVEAUX NOUVO) +(CHIEN CHIENS CHIN) +(GARDE GARDES GARD)' IN BOOLEAN MODE) or MATCH(editeur) AGAINST('+(RAISON RAISONS RAISON) +(D00 D00S ) +(AGIR AGIRS AJIR)' IN BOOLEAN MODE) and date_creation >'2012-02-03' and MATCH(facettes) AGAINST('+B4' IN BOOLEAN MODE)")], + 'req_comptage' => $this->countSqlWith("date_creation >'2012-02-03' and (MATCH(titres) AGAINST('+(NOUVEAU NOUVEAUX NOUVO) +(CHIEN CHIENS CHIN) +(GARDE GARDES GARD)' IN BOOLEAN MODE) or MATCH(editeur) AGAINST('+(RAISON RAISONS RAISON) +(D00 D00S ) +(AGIR AGIRS AJIR)' IN BOOLEAN MODE)) and MATCH(facettes) AGAINST('+B4' IN BOOLEAN MODE)"), + 'req_facettes' => $this->facetSqlWith("date_creation >'2012-02-03' and (MATCH(titres) AGAINST('+(NOUVEAU NOUVEAUX NOUVO) +(CHIEN CHIENS CHIN) +(GARDE GARDES GARD)' IN BOOLEAN MODE) or MATCH(editeur) AGAINST('+(RAISON RAISONS RAISON) +(D00 D00S ) +(AGIR AGIRS AJIR)' IN BOOLEAN MODE)) and MATCH(facettes) AGAINST('+B4' IN BOOLEAN MODE)")], [['rech_auteurs' => 'Stiegler', 'operateur_auteurs' => 'and', @@ -178,10 +178,10 @@ class MoteurRechercheAvanceeTest extends MoteurRechercheTestCase { 'type_recherche' => 'commence', 'pertinence' => true, 'tri' => 'alpha_titre'] , - 'req_notices' => $this->listSqlWith("auteurs like 'STIEGLER%' and MATCH(facettes) AGAINST('+YMED1 +G23 +A345 +(YTUN YTAP) +(S1 S12 S9) +(B3 B4)' IN BOOLEAN MODE)", + 'req_notices' => $this->listSqlWith("(auteurs like 'STIEGLER%') and MATCH(facettes) AGAINST('+YMED1 +G23 +A345 +(YTUN YTAP) +(S1 S12 S9) +(B3 B4)' IN BOOLEAN MODE)", 'alpha_titre'), - 'req_comptage' => $this->countSqlWith("auteurs like 'STIEGLER%' and MATCH(facettes) AGAINST('+YMED1 +G23 +A345 +(YTUN YTAP) +(S1 S12 S9) +(B3 B4)' IN BOOLEAN MODE)"), - 'req_facettes' => $this->facetSqlWith("auteurs like 'STIEGLER%' and MATCH(facettes) AGAINST('+YMED1 +G23 +A345 +(YTUN YTAP) +(S1 S12 S9) +(B3 B4)' IN BOOLEAN MODE)")], + 'req_comptage' => $this->countSqlWith("(auteurs like 'STIEGLER%') and MATCH(facettes) AGAINST('+YMED1 +G23 +A345 +(YTUN YTAP) +(S1 S12 S9) +(B3 B4)' IN BOOLEAN MODE)"), + 'req_facettes' => $this->facetSqlWith("(auteurs like 'STIEGLER%') and MATCH(facettes) AGAINST('+YMED1 +G23 +A345 +(YTUN YTAP) +(S1 S12 S9) +(B3 B4)' IN BOOLEAN MODE)")], [['rech_titres' => 'Les décisions absurdes', 'operateur_auteurs' => 'and', @@ -193,10 +193,10 @@ class MoteurRechercheAvanceeTest extends MoteurRechercheTestCase { 'type_recherche' => 'commence', 'pertinence' => true, 'tri' => 'alpha_titre'], - 'req_notices' => $this->listSqlWith("titres like 'LES DECISIONS ABSURDES%' and MATCH(facettes) AGAINST('+S1 +YMED1 +M4669 +(YTUN YTAP) +(B3 B4)' IN BOOLEAN MODE)", + 'req_notices' => $this->listSqlWith("(titres like 'LES DECISIONS ABSURDES%') and MATCH(facettes) AGAINST('+S1 +YMED1 +M4669 +(YTUN YTAP) +(B3 B4)' IN BOOLEAN MODE)", 'alpha_titre'), - 'req_comptage' => $this->countSqlWith("titres like 'LES DECISIONS ABSURDES%' and MATCH(facettes) AGAINST('+S1 +YMED1 +M4669 +(YTUN YTAP) +(B3 B4)' IN BOOLEAN MODE)"), - 'req_facettes' => $this->facetSqlWith("titres like 'LES DECISIONS ABSURDES%' and MATCH(facettes) AGAINST('+S1 +YMED1 +M4669 +(YTUN YTAP) +(B3 B4)' IN BOOLEAN MODE)")], + 'req_comptage' => $this->countSqlWith("(titres like 'LES DECISIONS ABSURDES%') and MATCH(facettes) AGAINST('+S1 +YMED1 +M4669 +(YTUN YTAP) +(B3 B4)' IN BOOLEAN MODE)"), + 'req_facettes' => $this->facetSqlWith("(titres like 'LES DECISIONS ABSURDES%') and MATCH(facettes) AGAINST('+S1 +YMED1 +M4669 +(YTUN YTAP) +(B3 B4)' IN BOOLEAN MODE)")], [['rech_auteurs' => 'Stiegler', 'operateur_auteurs' => 'and', @@ -208,10 +208,10 @@ class MoteurRechercheAvanceeTest extends MoteurRechercheTestCase { 'type_recherche' => 'commence', 'pertinence' => true, 'tri' => 'alpha_titre'] , - 'req_notices' => $this->listSqlWith("auteurs like 'STIEGLER%' and MATCH(facettes) AGAINST('+YMED1 +G23 +A345 +(YTUN YTAP) +(S1 S12 S9) +(B3)' IN BOOLEAN MODE)", + 'req_notices' => $this->listSqlWith("(auteurs like 'STIEGLER%') and MATCH(facettes) AGAINST('+YMED1 +G23 +A345 +(YTUN YTAP) +(S1 S12 S9) +(B3)' IN BOOLEAN MODE)", 'alpha_titre'), - 'req_comptage' => $this->countSqlWith("auteurs like 'STIEGLER%' and MATCH(facettes) AGAINST('+YMED1 +G23 +A345 +(YTUN YTAP) +(S1 S12 S9) +(B3)' IN BOOLEAN MODE)"), - 'req_facettes' => $this->facetSqlWith("auteurs like 'STIEGLER%' and MATCH(facettes) AGAINST('+YMED1 +G23 +A345 +(YTUN YTAP) +(S1 S12 S9) +(B3)' IN BOOLEAN MODE)")]]; + 'req_comptage' => $this->countSqlWith("(auteurs like 'STIEGLER%') and MATCH(facettes) AGAINST('+YMED1 +G23 +A345 +(YTUN YTAP) +(S1 S12 S9) +(B3)' IN BOOLEAN MODE)"), + 'req_facettes' => $this->facetSqlWith("(auteurs like 'STIEGLER%') and MATCH(facettes) AGAINST('+YMED1 +G23 +A345 +(YTUN YTAP) +(S1 S12 S9) +(B3)' IN BOOLEAN MODE)")]]; }