diff --git a/VERSIONS_HOTLINE/204286 b/VERSIONS_HOTLINE/204286 new file mode 100644 index 0000000000000000000000000000000000000000..8486d1eb0bdf8c70d77b42c11fdbf532327c2f7a --- /dev/null +++ b/VERSIONS_HOTLINE/204286 @@ -0,0 +1 @@ + - correctif #204286 : Recherche : Les filtres de profil ne doivent pas écraser l'affinage utilisateur. \ No newline at end of file diff --git a/library/Class/MoteurRecherche/Clauses.php b/library/Class/MoteurRecherche/Clauses.php index 6eadb52e7cfacfac0c65513b247695390c1c0df9..4fb95cba735655b85b62d6cd7bc7d576fa05a9c1 100644 --- a/library/Class/MoteurRecherche/Clauses.php +++ b/library/Class/MoteurRecherche/Clauses.php @@ -173,13 +173,30 @@ class Class_MoteurRecherche_Clauses { public function visitMultiFacet(string $multi_facet): void + { + if ($code = $this->_codeMultiFacet($multi_facet)) + $this->_match_axes->addMultiFacet($code, Class_Notice_Facettes::PREFIX . $multi_facet); + } + + + public function visitFilterMultiFacet(string $multi_facet): self + { + if ($code = $this->_codeMultiFacet($multi_facet)) + $this->_match_axes->addFilterMultiFacet($code, Class_Notice_Facettes::PREFIX . $multi_facet); + + return $this; + } + + + protected function _codeMultiFacet(string $multi_facet): string { if ( ! $multi_facet) - return; + return ''; $facet = Class_Facet::find($multi_facet); - if ($facet && ($code = $facet->getCodeRubrique())) - $this->_match_axes->addMultiFacet($code, Class_Notice_Facettes::PREFIX . $multi_facet); + return ($facet && ($code = $facet->getCodeRubrique())) + ? $code + : ''; } @@ -348,7 +365,7 @@ class Class_MoteurRecherche_Clauses { public function visitFiltre(array $facets) : void { foreach ($facets as $facet) - $this->visitMultiFacet($facet); + $this->visitFilterMultiFacet($facet); } diff --git a/library/Class/MoteurRecherche/MatchAxes.php b/library/Class/MoteurRecherche/MatchAxes.php index ef12af8a7324396d6b4990616c2ed1ab4a3efa1a..fa681663d6843882516c8104c8fbeb9ba8c4080a 100644 --- a/library/Class/MoteurRecherche/MatchAxes.php +++ b/library/Class/MoteurRecherche/MatchAxes.php @@ -28,6 +28,7 @@ class Class_MoteurRecherche_MatchAxes protected string $_or_domain = ''; protected Class_MoteurRecherche_MatchAxesVariantsWords $_variants_words; protected ?Storm_Collection $_multi_facets = null; + protected ?Storm_Collection $_filter_multi_facets = null; protected ?Storm_Query_MatchBoolean $_match_axes = null; protected ?Storm_Query_MatchBoolean $_match_in_file = null; @@ -71,14 +72,19 @@ class Class_MoteurRecherche_MatchAxes foreach (array_unique(array_filter($this->_and_facets)) as $facet) $this->_matchAllAxes()->against_and($facet); - if ( ! $this->_multi_facets) - return $this; + if ($this->_multi_facets) + $this->_multi_facets->eachDo(function($multi) + { + if ($multi_facets = $multi->compose()) + $this->_matchAllAxes()->against_and($multi_facets); + }); - $this->_multi_facets->eachDo(function($multi) - { - if ($multi_facets = $multi->compose()) - $this->_matchAllAxes()->against_and($multi_facets); - }); + if ($this->_filter_multi_facets) + $this->_filter_multi_facets->eachDo(function($multi) + { + if ($multi_facets = $multi->compose()) + $this->_matchAllAxes()->against_and($multi_facets); + }); return $this; } @@ -100,6 +106,13 @@ class Class_MoteurRecherche_MatchAxes $match_terms [] = Storm_Query_Terms::and($multi_facets); }); + if ($this->_filter_multi_facets) + $this->_filter_multi_facets->eachDo(function($multi) use (&$match_terms) + { + if ($multi_facets = $multi->compose()) + $match_terms [] = Storm_Query_Terms::and($multi_facets); + }); + if ( ! $match_terms) { $this->_matchAllAxes()->against_or($this->_or_domain); @@ -148,6 +161,23 @@ class Class_MoteurRecherche_MatchAxes } + public function addFilterMultiFacet(string $code, string $facet): self + { + $multi_facet = $this->_filterMultiFacets() + ->detect(fn($multi) => $multi->isSameCode($code)); + + if ( ! $multi_facet) + { + $multi_facet = new Class_MoteurRecherche_MatchAxesMultiFacets($code); + $this->_filterMultiFacets()->add($multi_facet); + } + + $multi_facet->addMultiFacet($facet); + + return $this; + } + + public function addFileContent(string $expression): self { if ($expression) @@ -181,6 +211,12 @@ class Class_MoteurRecherche_MatchAxes } + protected function _filterMultiFacets(): Storm_Collection + { + return $this->_filter_multi_facets ??= new Storm_Collection; + } + + protected function _matchAllAxes(): Storm_Query_MatchBoolean { return $this->_match_axes diff --git a/tests/library/Class/MoteurRechercheTest.php b/tests/library/Class/MoteurRechercheTest.php index c76c6ba5b8e8cf4c98343dc21c02869d51d49c91..e0d62b4c18f19a55a485ae985632bee004a67788 100644 --- a/tests/library/Class/MoteurRechercheTest.php +++ b/tests/library/Class/MoteurRechercheTest.php @@ -100,7 +100,7 @@ class MoteurRechercheAvanceeTest extends MoteurRechercheTestCase { 'operateur_titres' => 'and', 'rech_editeur' => 'Raisons d\'agir', 'operateur_editeur' => 'or', - 'selection_bib'=> 4, + 'selection_bib' => 4, 'nouveaute' => '3', 'type_recherche' => 'nimportequoi', 'pertinence' => false, @@ -150,7 +150,7 @@ class MoteurRechercheAvanceeTest extends MoteurRechercheTestCase { 'type_recherche' => 'commence', 'pertinence' => true, 'tri' => 'alpha_titre'], - 'sql' => "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE ((`notices`.`auteurs` LIKE 'P_CLASTRES%' AND MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+(F_YMED1 F_YTUN F_YTAP)' IN BOOLEAN MODE)) AND `notices`.`type` = 1) ORDER BY `notices`.`alpha_titre` ASC"], + 'sql' => "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE ((`notices`.`auteurs` LIKE 'P_CLASTRES%' AND MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+F_YMED1 +(F_YTUN F_YTAP)' IN BOOLEAN MODE)) AND `notices`.`type` = 1) ORDER BY `notices`.`alpha_titre` ASC"], [['rech_matieres' => 'Philosophie', 'operateur_matieres' => 'and not', @@ -195,7 +195,7 @@ class MoteurRechercheAvanceeTest extends MoteurRechercheTestCase { 'type_recherche' => 'commence', 'pertinence' => true, 'tri' => 'alpha_titre'], - 'sql' => "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE ((`notices`.`auteurs` LIKE 'P_STIEGLER%' AND MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+F_G23 +F_A345 +(F_YMED1 F_YTUN F_YTAP) +(F_S1 F_S12 F_S9) +(F_B3 F_B4)' IN BOOLEAN MODE)) AND `notices`.`type` = 1) ORDER BY `notices`.`alpha_titre` ASC"], + 'sql' => "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE ((`notices`.`auteurs` LIKE 'P_STIEGLER%' AND MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+F_G23 +F_A345 +F_YMED1 +(F_YTUN F_YTAP) +(F_S1 F_S12 F_S9) +(F_B3 F_B4)' IN BOOLEAN MODE)) AND `notices`.`type` = 1) ORDER BY `notices`.`alpha_titre` ASC"], [['rech_titres' => 'Les décisions absurdes', 'operateur_auteurs' => 'and', @@ -207,7 +207,7 @@ class MoteurRechercheAvanceeTest extends MoteurRechercheTestCase { 'type_recherche' => 'commence', 'pertinence' => true, 'tri' => 'alpha_titre'], - 'sql' => "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE ((`notices`.`titres` LIKE 'P_LES P_DECISIONS P_ABSURDES%' AND MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+F_M4669 +F_S1 +(F_YMED1 F_YTUN F_YTAP) +(F_B3 F_B4)' IN BOOLEAN MODE)) AND `notices`.`type` = 1) ORDER BY `notices`.`alpha_titre` ASC"], + 'sql' => "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE ((`notices`.`titres` LIKE 'P_LES P_DECISIONS P_ABSURDES%' AND MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+F_M4669 +F_S1 +F_YMED1 +(F_YTUN F_YTAP) +(F_B3 F_B4)' IN BOOLEAN MODE)) AND `notices`.`type` = 1) ORDER BY `notices`.`alpha_titre` ASC"], [['rech_auteurs' => 'Stiegler', 'operateur_auteurs' => 'and', @@ -220,7 +220,7 @@ class MoteurRechercheAvanceeTest extends MoteurRechercheTestCase { 'type_recherche' => 'commence', 'pertinence' => true, 'tri' => 'alpha_titre'], - 'sql' => "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE ((`notices`.`auteurs` LIKE 'P_STIEGLER%' AND MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+F_G23 +F_A345 +(F_YMED1 F_YTUN F_YTAP) +(F_T1 F_Tbokeh_page) +(F_S1 F_S12 F_S9) +F_B3' IN BOOLEAN MODE)) AND `notices`.`type` = 1) ORDER BY `notices`.`alpha_titre` ASC"], + 'sql' => "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE ((`notices`.`auteurs` LIKE 'P_STIEGLER%' AND MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+F_G23 +F_A345 +F_YMED1 +(F_T1 F_Tbokeh_page) +(F_YTUN F_YTAP) +(F_S1 F_S12 F_S9) +F_B3' IN BOOLEAN MODE)) AND `notices`.`type` = 1) ORDER BY `notices`.`alpha_titre` ASC"], [['rech_titres' => 'parquets', 'operateur_titres' => 'and'], @@ -318,7 +318,7 @@ class MoteurRechercheSimpleTest extends MoteurRechercheTestCase { 'selection_annexe' => 'TUN;TAP', 'tri' => 'alpha_titre', 'no_extension' => '1'], - 'sql' => "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE (MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+(COMMUNE COMMUNES KOMUN) +(PARI PARIS) +(F_YMED1 F_YTUN F_YTAP)' IN BOOLEAN MODE) AND `notices`.`type` = 1) ORDER BY `notices`.`alpha_titre` ASC"], + 'sql' => "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE (MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+(COMMUNE COMMUNES KOMUN) +(PARI PARIS) +F_YMED1 +(F_YTUN F_YTAP)' IN BOOLEAN MODE) AND `notices`.`type` = 1) ORDER BY `notices`.`alpha_titre` ASC"], [['expressionRecherche' => '2-7427-3315-9', 'geo_zone' => 2, @@ -353,7 +353,7 @@ class MoteurRechercheSimpleTest extends MoteurRechercheTestCase { 'selection_annexe' => 'TUN;TAP', 'selection_sections' => '1;12;9', 'no_extension' => '1'], - 'sql' => "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE (MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+(LOGO LOGOS) +F_M52291 +F_A15067 +(F_YMED1 F_YTUN F_YTAP) +(F_S1 F_S12 F_S9)' IN BOOLEAN MODE) AND `notices`.`type` = 1) ORDER BY MATCH(`notices`.`auteurs`) AGAINST('P_LOGO') DESC, MATCH(`notices`.`titres`) AGAINST('P_LOGO') DESC, MATCH(`notices`.`titres`) AGAINST('LOGO') DESC, MATCH(`notices`.`auteurs`) AGAINST('LOGO') DESC, `notices`.`date_creation` DESC"], + 'sql' => "SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE (MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+(LOGO LOGOS) +F_M52291 +F_A15067 +F_YMED1 +(F_YTUN F_YTAP) +(F_S1 F_S12 F_S9)' IN BOOLEAN MODE) AND `notices`.`type` = 1) ORDER BY MATCH(`notices`.`auteurs`) AGAINST('P_LOGO') DESC, MATCH(`notices`.`titres`) AGAINST('P_LOGO') DESC, MATCH(`notices`.`titres`) AGAINST('LOGO') DESC, MATCH(`notices`.`auteurs`) AGAINST('LOGO') DESC, `notices`.`date_creation` DESC"], [['expressionRecherche' => 'logo', 'multifacets' => 'Tper_title', @@ -883,7 +883,7 @@ class MoteurRechercheWithCatalogueAndParamsTest (new Class_MoteurRecherche)->lancerRecherche($criteres_recherche); $this->assertSqlEquals(["UPDATE `notices` SET `facettes` = CLEAN_SPACES(REGEXP_REPLACE(`facettes`, '\\\\bHCCCC0001\\\\b', '')), `facets` = CLEAN_SPACES(REGEXP_REPLACE(`facets`, '\\\\bF_HCCCC0001\\\\b', '')) WHERE (`notices`.`type_doc` NOT IN (8, 9, 10) AND `notices`.`type` = 1 AND MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+F_HCCCC0001' IN BOOLEAN MODE))", - 'SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE ((`notices`.`date_creation` >= \'2014-12-23\' AND MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST(\'+((+F_P4* +(F_Y2 F_Y4 F_Y1) +(F_T1 F_T4)) F_Q5)\' IN BOOLEAN MODE)) AND `notices`.`type` = 1) ORDER BY `notices`.`date_creation` DESC']); + 'SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE ((`notices`.`date_creation` >= \'2014-12-23\' AND MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST(\'+((+F_P4* +(F_T1 F_T4) +(F_Y2 F_Y4 F_Y1)) F_Q5)\' IN BOOLEAN MODE)) AND `notices`.`type` = 1) ORDER BY `notices`.`date_creation` DESC']); } } @@ -1114,3 +1114,22 @@ class MoteurRechercheCountWordsTest extends MoteurRechercheTestCase { $this->assertEquals($count_words, $result->getWordCount()); } } + + + + +class MoteurRechercheFacetTypeDocWithFiltreTypeDocTest + extends MoteurRechercheWithCatalogueTestCase +{ + + /** @test */ + public function requestShouldContainsProfilSettings() + { + Class_Profil::getCurrentProfil()->setSelTypeDoc('2;4;1'); + + (new Class_MoteurRecherche) + ->lancerRecherche((new Class_CriteresRecherche)->setParams(['multifacets' => 'T5'])); + + $this->assertSql("SELECT `notices`.`id_notice`, `notices`.`facettes` FROM `notices` WHERE (MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+F_T5 +(F_T2 F_T4 F_T1)' IN BOOLEAN MODE) AND `notices`.`type` = 1)"); + } +}