From 2e2ba5d59a6e0c56482f271c64951b53be621aa5 Mon Sep 17 00:00:00 2001 From: pbarroca <pbarroca@afi-sa.fr> Date: Fri, 10 Oct 2014 19:10:39 +0200 Subject: [PATCH] fix #16765 : remove method containing subselect on records to extract id_notice, give responsibility to user code to give a tuned query to retreive ids only --- library/Class/Catalogue.php | 274 +++---- library/Class/MoteurRecherche.php | 321 ++++---- library/Class/Notice.php | 24 +- library/Class/Notice/NavigationRecherche.php | 14 +- library/ZendAfi/View/Helper/Accueil/Base.php | 13 +- .../ZendAfi/View/Helper/Accueil/Kiosque.php | 12 +- .../controllers/RechercheControllerTest.php | 15 +- tests/library/Class/CatalogueTest.php | 85 +- tests/library/Class/ListesNoticesTest.php | 47 +- tests/library/Class/MoteurRechercheTest.php | 739 +++++++++--------- .../View/Helper/Accueil/KiosqueTest.php | 33 +- 11 files changed, 768 insertions(+), 809 deletions(-) diff --git a/library/Class/Catalogue.php b/library/Class/Catalogue.php index defc18aebcc..d33514042e1 100644 --- a/library/Class/Catalogue.php +++ b/library/Class/Catalogue.php @@ -16,13 +16,13 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with AFI-OPAC 2.0; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ //////////////////////////////////////////////////////////////////////////////// // OPAC3 - Catalogues de notices //////////////////////////////////////////////////////////////////////////////// class CatalogueLoader extends Storm_Model_Loader { - + const DEFAULT_ITEMS_BY_PAGE = 100; public function loadNoticesFor($catalogue, $itemsByPage = self::DEFAULT_ITEMS_BY_PAGE, $page = 1, $find_all_params = null) { @@ -37,7 +37,7 @@ class CatalogueLoader extends Storm_Model_Loader { if ('' == ($where = $this->clausesFor($catalogue))) return array(); - + $find_all_params['where'] = $where; return Class_Notice::getLoader()->findAllBy($find_all_params); } @@ -48,7 +48,7 @@ class CatalogueLoader extends Storm_Model_Loader { return $catalogues; } - + public function getDomainsForBreadcrumb($breadcrumb) { $domains_ids=array_filter(explode(';',$breadcrumb)); $domains=[]; @@ -77,7 +77,7 @@ class CatalogueLoader extends Storm_Model_Loader { public function countNoticesFor($catalogue) { if (!$catalogue) return 0; - + if ('' == ($where = $this->clausesFor($catalogue))) return 0; @@ -96,11 +96,11 @@ class CatalogueLoader extends Storm_Model_Loader { if ($facets = $this->facetsClauseFor($catalogue)) $conditions[] = $facets; - - if ($docType = $this->docTypeClauseFor($catalogue)) + + if ($docType = $this->docTypeClauseFor($catalogue)) $conditions[] = $docType; - if ($year = $this->yearClauseFor($catalogue)) + if ($year = $this->yearClauseFor($catalogue)) $conditions[] = $year; if ($cote = $this->coteClauseFor($catalogue)) @@ -112,7 +112,7 @@ class CatalogueLoader extends Storm_Model_Loader { if (0 == count($conditions)) return ''; - + return implode(' and ', $conditions); } @@ -130,9 +130,9 @@ class CatalogueLoader extends Storm_Model_Loader { 'Y' => $catalogue->getAnnexe(), 'E' => $catalogue->getEmplacement()); - foreach ($facets as $k => $v) + foreach ($facets as $k => $v) $against .= Class_Catalogue::getSelectionFacette($k, $v); - + $facets = array('A' => $catalogue->getAuteur(), 'M' => $catalogue->getMatiere(), 'D' => $catalogue->getDewey(), @@ -141,11 +141,11 @@ class CatalogueLoader extends Storm_Model_Loader { 'Z' => $catalogue->getTags(), 'F' => $catalogue->getInteret()); - foreach ($facets as $k => $v) + foreach ($facets as $k => $v) $against_ou .= Class_Catalogue::getSelectionFacette($k, $v, in_array($k, array('M', 'D', 'P','H')), false); - if ('' != $against_ou) + if ('' != $against_ou) $against .= ' +(' . $against_ou . ")"; if ('' == $against) @@ -160,7 +160,7 @@ class CatalogueLoader extends Storm_Model_Loader { return ''; $parts = array_filter(explode(';', $docType)); - if (1 == count($parts)) + if (1 == count($parts)) return 'type_doc=' . $parts[0]; return 'type_doc IN (' . implode(', ', $parts) . ')'; @@ -169,10 +169,10 @@ class CatalogueLoader extends Storm_Model_Loader { public function yearClauseFor($catalogue) { $clauses = array(); - if ($start = $catalogue->getAnneeDebut()) + if ($start = $catalogue->getAnneeDebut()) $clauses[] = "annee >= '" . $start . "'"; - if($end = $catalogue->getAnneeFin()) + if($end = $catalogue->getAnneeFin()) $clauses[] = "annee <= '" . $end . "'"; if (0 == count($clauses)) @@ -184,10 +184,10 @@ class CatalogueLoader extends Storm_Model_Loader { public function coteClauseFor($catalogue) { $clauses = array(); - if ($start = $catalogue->getCoteDebut()) + if ($start = $catalogue->getCoteDebut()) $clauses[] = "cote >= '" . strtoupper($start) . "'"; - if ($end = $catalogue->getCoteFin()) + if ($end = $catalogue->getCoteFin()) $clauses[] = "cote <= '". strtoupper($end) . "'"; if (0 == count($clauses)) @@ -209,10 +209,10 @@ class CatalogueLoader extends Storm_Model_Loader { public function fromUntilClauseFor($catalogue) { $clauses = array(); - if ($start = $catalogue->getFrom()) + if ($start = $catalogue->getFrom()) $clauses[] = "left(date_maj, 10) >= '" . $start . "'"; - if($end = $catalogue->getUntil()) + if($end = $catalogue->getUntil()) $clauses[] = "left(date_maj, 10) <= '" . $end . "'"; if (0 == count($clauses)) @@ -248,7 +248,7 @@ class CatalogueLoader extends Storm_Model_Loader { * @return Class_Catalogue */ public function getRoot() { - return Class_Catalogue::newInstanceWithId(null, + return Class_Catalogue::newInstanceWithId(null, ['sous_domaines' => Class_Catalogue::findTopCatalogues()]); } @@ -262,24 +262,24 @@ class CatalogueLoader extends Storm_Model_Loader { } public function fetchAllNoticesByPreferences($preferences, $cache_vignette) { - $requetes=$this->getRequetes($preferences); + $requetes = $this->getRequetes($preferences); if (!array_key_exists("req_liste", $requetes)) return array(); $req_liste = str_replace('select *', - 'select notices.id_notice, notices.editeur, notices.annee, notices.date_creation, notices.date_maj, notices.facettes, notices.clef_oeuvre', + 'select notices.id_notice, notices.editeur, notices.annee, notices.date_creation, notices.date_maj, notices.facettes, notices.clef_oeuvre', $requetes["req_liste"]); - $catalogue=fetchAll($req_liste); - if (!$catalogue) + $catalogue = fetchAll($req_liste); + if (!$catalogue) return []; - + $class_notice = new Class_Notice(); $class_img = new Class_WebService_Vignette(); - + $notices = []; foreach($catalogue as $notice) { - $enreg = ($model = Class_Notice::find($notice['id_notice'])) + $enreg = ($model = Class_Notice::find($notice['id_notice'])) ? $model->getNotice('JA') : []; $vignette = ''; if ($cache_vignette) { @@ -289,7 +289,7 @@ class CatalogueLoader extends Storm_Model_Loader { if (!$cache_vignette or $vignette) { $notices[] = ["id_notice" => $enreg["id_notice"], - "titre" => $enreg["J"], + "titre" => $enreg["J"], "auteur" => $enreg["A"], "vignette" => $vignette, "type_doc" => $enreg["type_doc"], @@ -305,45 +305,50 @@ class CatalogueLoader extends Storm_Model_Loader { return $notices; } + public function getRequetes($preferences, $fields = null) { if (isset($preferences["id_panier"]) - && (0 !== (int)$preferences["id_panier"])) + && (0 !== (int)$preferences["id_panier"])) return $this->getRequetesPanier($preferences); $against = $this->selectionFacettesForCatalogueRequestByPreferences($preferences); if ($catalogue = $this->find($preferences['id_catalogue'])) { - $conditions = array($this->facetsClauseFor($catalogue, $against)); + $conditions = [$this->facetsClauseFor($catalogue, $against)]; $conditions []= $this->docTypeClauseFor($catalogue); $conditions []= $this->yearClauseFor($catalogue); $conditions []= $this->coteClauseFor($catalogue); $conditions []= $this->nouveauteClauseFor($catalogue); } else { - $conditions = $against ? array("MATCH(facettes) AGAINST('".$against."' IN BOOLEAN MODE)") : array(); + $conditions = $against + ? ["MATCH(facettes) AGAINST('" . $against . "' IN BOOLEAN MODE)"] + : []; } - if (isset($preferences['only_img']) && ($preferences['only_img'] == 1)) + if (isset($preferences['only_img']) && ($preferences['only_img'] == 1)) $conditions[] = "url_vignette > '' and url_vignette != 'NO'"; - $join = (isset($preferences['avec_avis']) && ($preferences['avec_avis'] == 1)) + $join = (isset($preferences['avec_avis']) && ($preferences['avec_avis'] == 1)) ? ' INNER JOIN notices_avis ON notices.clef_oeuvre=notices_avis.clef_oeuvre ' : ''; if ($where = implode(' and ', array_filter($conditions))) - $where = ' where '.$where; + $where = ' where ' . $where; $order_by = $this->orderByForCatalogueRequestByPreferences($preferences); $limite = $this->limitForCatalogueRequestByPreferences($preferences); - $select_fields = $fields ? implode(',', $fields): '*'; + $sql = 'select %s from notices' . $join . $where; - $ret['req_liste'] = 'select ' . $select_fields . ' from notices ' . $join . $where . $order_by . $limite; - $ret['req_comptage'] = 'select count(*) from notices ' . $join . $where; - $ret['req_facettes'] = 'select notices.id_notice, type_doc, facettes from notices ' . $join . $where . $limite; - - return $ret; + return ['req_liste' => sprintf($sql, $fields ? implode(',', $fields) : '*') + . $order_by . $limite, + 'req_comptage' => sprintf($sql, 'count(*)'), + 'req_facettes' => sprintf($sql, 'notices.id_notice, type_doc, facettes') + . $limite, + 'req_ids' => sprintf($sql, 'notices.id_notice') . $order_by . $limite]; } + public function selectionFacettesForCatalogueRequestByPreferences($preferences) { if (!isset($preferences['facettes'])) return ''; @@ -351,7 +356,7 @@ class CatalogueLoader extends Storm_Model_Loader { $against = ''; $facettes = explode(';', $preferences['facettes']); foreach($facettes as $facette) { - $facette = trim($facette); + $facette = trim($facette); $against .= $this->getSelectionFacette(substr($facette, 0, 1), substr($facette, 1)); } @@ -359,14 +364,14 @@ class CatalogueLoader extends Storm_Model_Loader { } public function orderByForCatalogueRequestByPreferences($preferences) { - if(!array_key_exists('tri', $preferences) - || ($preferences["tri"] == '0' + if(!array_key_exists('tri', $preferences) + || ($preferences["tri"] == '0' || $preferences["tri"] == 'alpha_titre')) return ' order by alpha_titre '; - + if ($preferences['tri'] == '1' || $preferences['tri'] == 'date_creation desc') return ' order by date_creation DESC '; - + if ($preferences['tri'] == '2' || $preferences['tri'] == 'nb_visu desc') return ' order by nb_visu DESC '; @@ -378,20 +383,20 @@ class CatalogueLoader extends Storm_Model_Loader { public function limitForCatalogueRequestByPreferences($preferences, $no_limit=false) { $limite = 0; - if (isset($preferences["aleatoire"]) && (int)$preferences["aleatoire"]==1) + if (isset($preferences["aleatoire"]) && (int)$preferences["aleatoire"]==1) $limite = (int)$preferences["nb_analyse"]; else if (isset($preferences['nb_notices'])) $limite = (int)$preferences["nb_notices"]; - if ($limite and !$no_limit) + if ($limite and !$no_limit) return ' LIMIT 0,' . $limite; return ' LIMIT 5000'; //LL: j'ai rajouté une limite max car explosion mémoire sur des catalogues mal définis } - + public static function getSelectionFacette($type, $valeurs, $descendants = false, $signe = true) { - if (!$valeurs) + if (!$valeurs) return false; $valeurs = explode(';', $valeurs); @@ -412,7 +417,7 @@ class CatalogueLoader extends Storm_Model_Loader { if (!$matiere = Class_Matiere::getLoader()->find($valeur)) continue; - + if ('' != ($sous_vedettes = trim($matiere->getSousVedettes()))) $valeur .= str_replace(' ', ' M', ' ' . $sous_vedettes); $cond .= $type . $valeur . ' '; @@ -423,86 +428,85 @@ class CatalogueLoader extends Storm_Model_Loader { return ($signe) ? ' +(' . $cond . ')' : ' ' . $cond; } + public function getRequetesPanier($preferences) { $panier = null; - if (array_key_exists('id_user', $preferences)) $panier = Class_PanierNotice::findFirstBy(['id_user' => $preferences['id_user'], 'id_panier' => $preferences['id_panier']]); - if (!$panier) $panier = Class_PanierNotice::find($preferences['id_panier']); - if (!$panier) + if (!$panier) return ['nombre' => 0]; $cles_notices = $panier->getClesNotices(); - if (empty($cles_notices)) { - $ret['nombre'] = 0; - return $ret; - } - - $in_sql = ''; + if (empty($cles_notices)) + return ['nombre' => 0]; + + $keys = []; foreach($cles_notices as $notice) { - if (!trim($notice)) continue; - $in_sql .= ('' != $in_sql ? ',' : '') . "'" . $notice . "'"; + if (!trim($notice)) + continue; + $keys[] = "'" . $notice . "'"; } + $in_sql = implode(',', $keys); - if ($preferences['aleatoire'] == 1) - $limite = $preferences['nb_analyse']; - else - $limite = $preferences['nb_notices']; - - if ($limite) - $limite = 'LIMIT 0,' . $limite; - else - $limite = ''; + $limite = ($preferences['aleatoire'] == 1) + ? $preferences['nb_analyse'] : $preferences['nb_notices']; + $limite = ($limite) ? 'LIMIT 0,' . $limite : ''; $order_by = ''; - if($preferences["tri"]==0) + if($preferences["tri"]==0) $order_by=" order by alpha_titre "; - if($preferences["tri"]==1) + if($preferences["tri"]==1) $order_by=" order by date_creation DESC "; - if($preferences["tri"]==2) + if($preferences["tri"]==2) $order_by=" order by nb_visu DESC "; - $condition = ''; - if (array_isset("only_img", $preferences) && $preferences["only_img"] == 1) - $condition=" and url_vignette > '' and url_vignette != 'NO' "; + $condition = (array_isset("only_img", $preferences) + && $preferences["only_img"] == 1) + ? " and url_vignette > '' and url_vignette != 'NO' " + : ''; + + $join = (array_isset("avec_avis", $preferences) && $preferences["avec_avis"] == 1) + ? ' INNER JOIN notices_avis ON notices.clef_oeuvre=notices_avis.clef_oeuvre ' + : ''; - $join = ''; - if (array_isset("avec_avis", $preferences) && $preferences["avec_avis"] == 1) - $join = " INNER JOIN notices_avis ON notices.clef_oeuvre=notices_avis.clef_oeuvre "; + $sql = 'select %s from notices ' + . $join + . 'where notices.clef_alpha in(' . $in_sql . ')' + . $condition; - $ret['req_liste'] = "select * from notices ".$join."where notices.clef_alpha in(".$in_sql.")".$condition.$order_by.$limite; - $ret['req_comptage'] = "select count(*) from notices ".$join."where notices.clef_alpha in(".$in_sql.")".$condition; - $ret['req_facettes'] = "select id_notice,type_doc,facettes from notices ".$join."where notices.clef_alpha in(".$in_sql.") ".$condition.$limite; - return $ret; + return ['req_liste' => sprintf($sql, '*') . $order_by . $limite, + 'req_comptage' => sprintf($sql, 'count(*)'), + 'req_facettes' => sprintf($sql, 'id_notice, type_doc, facettes') . $limite, + 'req_ids' => sprintf($sql, 'notices.id_notice') . $order_by . $limite]; } - - public function getNoticesFromCacheByPreferences($preferences, $cache_vignette) { + + public function getNoticesFromCacheByPreferences($preferences, $cache_vignette) { return (new Storm_Cache()) ->memoize([$preferences, __CLASS__, __FUNCTION__, $cache_vignette], function() use ($preferences, $cache_vignette) { - return Class_Catalogue::getLoader()->fetchAllNoticesByPreferences($preferences, $cache_vignette); + return Class_Catalogue::getLoader()->fetchAllNoticesByPreferences($preferences, $cache_vignette); }); } public function getNoticesByPreferences($preferences, $cache_vignette=false) { - if (isset($preferences['id_catalogue']) + if (isset($preferences['id_catalogue']) && ($catalogue = Class_Catalogue::getLoader()->find($preferences['id_catalogue']))) { $preferences['catalogue_cache_key'] = serialize($catalogue->toArray()); } $notices = $this->getNoticesFromCacheByPreferences($preferences, $cache_vignette); - if ((int)$preferences["aleatoire"] !== 1) + if ((int)$preferences["aleatoire"] !== 1) return $notices; shuffle($notices); - return array_slice ($notices, 0, $preferences["nb_notices"]); + return array_slice ($notices, 0, $preferences["nb_notices"]); } } @@ -512,8 +516,8 @@ class CatalogueLoader extends Storm_Model_Loader { class Class_Catalogue extends Storm_Model_Abstract { use Trait_TreeNode, Trait_Translator; - - protected + + protected $_table_name = 'catalogue', $_table_primary = 'ID_CATALOGUE', $_loader_class = 'CatalogueLoader', @@ -548,7 +552,7 @@ class Class_Catalogue extends Storm_Model_Abstract { 'user' => ['model' => 'Class_Users', 'referenced_in' => 'id_user'] ], - + $_has_many = ['sous_domaines' => ['model' => 'Class_Catalogue', 'role' => 'domaine_parent', 'dependents' => 'delete', @@ -563,7 +567,7 @@ class Class_Catalogue extends Storm_Model_Abstract { $_from, $_until; - + public static function newCatalogueForAll() { return new AllNoticesCatalogue(); } @@ -571,7 +575,7 @@ class Class_Catalogue extends Storm_Model_Abstract { /** [[file:~/public_html/afi-opac3/library/Trait/TreeNode.php::trait%20Trait_TreeNode%20{][voir Trait_TreeNode]] */ public function getParent() { - return $this->getDomaineParent(); + return $this->getDomaineParent(); } @@ -609,7 +613,7 @@ class Class_Catalogue extends Storm_Model_Abstract { $start=$nb_par_page*$numero_page; $requete_ids=str_replace('LIMIT 5000', - "limit ".$nb_par_page*$numero_page.','.$nb_par_page, + "limit ".$nb_par_page*$numero_page.','.$nb_par_page, $req['req_liste']); $sql = Zend_Registry::get('sql'); @@ -629,7 +633,7 @@ class Class_Catalogue extends Storm_Model_Abstract { * Sites, articles and RSS records are first destroyed and then get their own selection of domains. * So therauri facettes must not be deleted. By the way, need to find a nicer implementation ... */ - $query = + $query = 'update notices set facettes = clean_spaces(replace(facettes,"H'.$id_thesaurus.'","")) '. 'where type_doc not in ('.implode(',', [Class_TypeDoc::ARTICLE, Class_TypeDoc::RSS, Class_TypeDoc::SITE]).') '. 'and match(facettes) against("+H'.$id_thesaurus.'" in boolean mode)'; @@ -645,14 +649,14 @@ class Class_Catalogue extends Storm_Model_Abstract { $sql = Zend_Registry::get('sql'); $thesaurus=Class_CodifThesaurus::findThesaurusForCatalogue($this->getId()); - if (!$thesaurus) + if (!$thesaurus) $this->saveThesaurus(); if ($thesaurus) { if ($page==0) $this->deleteThesaurusInFacette($thesaurus->getIdThesaurus()); - + $sql->query('update notices set facettes=concat(facettes," H'.$thesaurus->getIdThesaurus().'") where id_notice in ('.implode(',',$ids).')'); return true; - + } return false; } @@ -662,7 +666,7 @@ class Class_Catalogue extends Storm_Model_Abstract { return Class_Catalogue::getLoader()->countNoticesFor($this); } - + public function isMatchingAllNotices() { return false; } @@ -680,7 +684,7 @@ class Class_Catalogue extends Storm_Model_Abstract { $ret["requete"] = $requetes["req_liste"]; $temps = time(); - $ret["notices"] = $this->getNotices(null, null, + $ret["notices"] = $this->getNotices(null, null, ['limitPage' => [1, $preferences['nb_notices']], 'order' => 'alpha_titre']); @@ -688,13 +692,13 @@ class Class_Catalogue extends Storm_Model_Abstract { $ret["nb_notices"] = fetchOne($requetes["req_comptage"]); $req = $requetes["req_comptage"]; - if (strpos($req,"where") > 0) - $req.=" and "; - else + if (strpos($req,"where") > 0) + $req.=" and "; + else $req.=" where "; $req .= "url_vignette > '' and url_vignette != 'NO'"; - $ret["avec_vignettes"] = fetchOne($req); + $ret["avec_vignettes"] = fetchOne($req); return $ret; } @@ -705,7 +709,7 @@ class Class_Catalogue extends Storm_Model_Abstract { if (!$v) continue; - $concat = ''; + $concat = ''; $values = array_filter(explode(';', $v)); foreach ($values as $value) { if (in_array($k, ['D', 'P', 'H'])) @@ -777,11 +781,11 @@ class Class_Catalogue extends Storm_Model_Abstract { public function getCatalogue($id_catalogue) { - return ($id_catalogue) + return ($id_catalogue) ? fetchEnreg("select * from catalogue where ID_CATALOGUE=$id_catalogue") : fetchAll("select * from catalogue order by LIBELLE"); } - + public static function getCataloguesForCombo() { if (!$catalogues = Class_Catalogue::findTopCatalogues()) @@ -819,7 +823,7 @@ class Class_Catalogue extends Storm_Model_Abstract { public function getChildren() { return $this->getSousDomaines(); } - + public function checkAndSetAnnee($attribute, $value) { $value = (int)$value; @@ -831,13 +835,13 @@ class Class_Catalogue extends Storm_Model_Abstract { public function validate() { $this->checkAttribute('libelle', $this->getLibelle(), 'Le libellé est requis'); - $this->checkAttribute('annee_fin', + $this->checkAttribute('annee_fin', !($this->getAnneeDebut() and $this->getAnneeFin()) || $this->getAnneeDebut() <= $this->getAnneeFin(), "L'année de début doit être inférieure ou égale à l'année de fin"); $this->checkAttribute('oai_spec', !$this->getOaiSpec() || preg_match('/^[a-zA-Z0-9_.-]+$/', $this->getOaiSpec()), - "La spec OAI ne peut contenir que les caractères suivants: de a à z, 0 à 9, - _ ."); - + "La spec OAI ne peut contenir que les caractères suivants: de a à z, 0 à 9, - _ ."); + } @@ -887,7 +891,7 @@ class Class_Catalogue extends Storm_Model_Abstract { '}'; } - + public function toDataForJson($options = []) { $data_domaines = []; $data_panier = []; @@ -925,7 +929,7 @@ class Class_Catalogue extends Storm_Model_Abstract { 'options' => array_merge(['ico' => URL_ADMIN_IMG.'picto/domaines_16.png'],$options)]; } - + public function afterSave(){ $this->saveThesaurus(); } @@ -965,8 +969,8 @@ class Class_Catalogue extends Storm_Model_Abstract { $thesaurus_parent = $catalogue_parent->saveThesauriParents(); if (!$thesaurus_parent) return null; - $new_thesaurus_id=Class_CodifThesaurus::findNextThesaurusChildId($thesaurus_parent->getIdThesaurus()); - $thesaurus->setIdThesaurus($new_thesaurus_id); + $new_thesaurus_id=Class_CodifThesaurus::findNextThesaurusChildId($thesaurus_parent->getIdThesaurus()); + $thesaurus->setIdThesaurus($new_thesaurus_id); $thesaurus->setLibelle($this->getLibelle()); $thesaurus->save(); return $thesaurus; @@ -976,12 +980,12 @@ class Class_Catalogue extends Storm_Model_Abstract { return $thesaurus; } - - + + public function saveThesaurus(){ if ($thesaurus=Class_CodifThesaurus::findThesaurusForCatalogue($this->getId())) $this->deleteThesaurusInFacette($thesaurus->getIdThesaurus()); - else + else if (!$thesaurus = $this->saveThesauriParents()) return; if($this->hasDomaineParent()){ @@ -993,26 +997,26 @@ class Class_Catalogue extends Storm_Model_Abstract { } else if (strlen($thesaurus->getIdThesaurus())>8) { $new_thesaurus_id=Class_CodifThesaurus::findNextRacineCatalogue();} - else + else return $thesaurus; if ($thesaurus->getId() && ($new_thesaurus_id != $thesaurus->getIdThesaurus())) { - $thesaurus->setIdThesaurus($new_thesaurus_id); + $thesaurus->setIdThesaurus($new_thesaurus_id); $thesaurus->setLibelle($this->getLibelle()); $thesaurus->save(); - + Class_Catalogue::getLoader()->updateAllThesaurusForCatalogueChildren($this->getId(),$new_thesaurus_id); return $thesaurus; } - $thesaurus->setIdThesaurus($new_thesaurus_id); + $thesaurus->setIdThesaurus($new_thesaurus_id); $thesaurus->setLibelle($this->getLibelle()); $thesaurus->save(); - + return $thesaurus; } - - + + public function startsWith($haystack, $needle) { return !strncmp($haystack, $needle, strlen($needle)); } @@ -1025,7 +1029,7 @@ class Class_Catalogue extends Storm_Model_Abstract { $thesaurus_ids = explode(';',$this->getThesaurus()); foreach($thesaurus_ids as $thesaurus_id) { if ($this->startsWith($thesaurus_id,$startWith)) { - if ($ids!='') + if ($ids!='') $ids.=';'; $ids.=$thesaurus_id; } @@ -1038,7 +1042,7 @@ class Class_Catalogue extends Storm_Model_Abstract { $thesaurus_ids=''; foreach (Class_CodifThesaurus::getIndices('root') as $thesaurus) { if (isset($req_attributes[$thesaurus->getIdThesaurus()])) { - if ($thesaurus_ids !='') + if ($thesaurus_ids !='') $thesaurus_ids.=';'; $thesaurus_ids.=$req_attributes[$thesaurus->getIdThesaurus()]; unset($req_attributes[$thesaurus->getIdThesaurus()]);} @@ -1058,8 +1062,8 @@ class Class_Catalogue extends Storm_Model_Abstract { if (!$user->hasRightToAccess(Class_UserGroup::RIGHT_USER_DOMAINES_SUPPRESSION_LIMIT)) return false; - - return ($this->hasUser() && + + return ($this->hasUser() && ($this->getUser()->getId() == $user->getId())); } @@ -1075,12 +1079,12 @@ class Class_Catalogue extends Storm_Model_Abstract { $copy = new Class_Catalogue(); $attributes = $this->_attributes; unset($attributes['id']); - + return $copy ->updateAttributes($attributes) ->setLibelle('** Nouveau Domaine **'); } - + public function getDomainesJson($options = []) { $domaines = Class_Catalogue::getLoader()->findTopCatalogues(); @@ -1095,7 +1099,7 @@ class Class_Catalogue extends Storm_Model_Abstract { 'items' => [], 'options' => ['ico' => URL_ADMIN_IMG.'picto/domaines_16.png', 'multipleSelection' => false]]; - + } @@ -1112,7 +1116,7 @@ class Class_Catalogue extends Storm_Model_Abstract { 'items' => [], 'options' => ['ico' => URL_ADMIN_IMG.'picto/domaines_16.png', 'multipleSelection' => false]]; - + } } diff --git a/library/Class/MoteurRecherche.php b/library/Class/MoteurRecherche.php index d7998fc14ca..98ea5bf2836 100644 --- a/library/Class/MoteurRecherche.php +++ b/library/Class/MoteurRecherche.php @@ -16,13 +16,13 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with AFI-OPAC 2.0; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class Class_MoteurRecherche { use Trait_Singleton, Trait_Translator, Trait_TimeSource; private $ix; // Classe d'indexation - private $limite_facettes = " limit 15000"; // limite pour le calcul des facettes + private $limite_facettes = ' limit 15000'; // limite pour le calcul des facettes protected $all_facettes; protected $_notices_not_shown = false; protected $fil_ariane; @@ -34,17 +34,22 @@ class Class_MoteurRecherche { public function createReqForIsbn($expression) { - if ($this->_isISBN($expression)) { - $cls = new Class_Isbn($expression); - $isbn = $cls->getAll(); - if ($isbn["isbn10"]) { - $this->setCondition("(isbn='".$isbn["isbn10"]."' or isbn='".$isbn["isbn13"]."')"); - return true; - } elseif($isbn["ean"]) { - $this->setCondition("ean='".$isbn["ean"]."'"); - return true; - } + if (!$this->_isISBN($expression)) + return false; + + $cls = new Class_Isbn($expression); + $isbn = $cls->getAll(); + + if ($isbn["isbn10"]) { + $this->setCondition("(isbn='".$isbn["isbn10"]."' or isbn='".$isbn["isbn13"]."')"); + return true; } + + if($isbn["ean"]) { + $this->setCondition("ean='".$isbn["ean"]."'"); + return true; + } + return false; } @@ -54,22 +59,20 @@ class Class_MoteurRecherche { } - public function visitSerie($serie,$tri) { - - $this->setCondition('clef_chapeau="'.$serie.'" '); - - if ($tri=='date_creation desc') - $this->order_by=" order by tome_alpha desc"; + public function visitSerie($serie, $tri) { + $this->setCondition('clef_chapeau="' . $serie . '" '); + if ($tri == 'date_creation desc') + $this->order_by = " order by tome_alpha desc"; } - + public function setErreur($message) { - $this->erreur["statut"] = 'erreur'; - $this->erreur["erreur"] = $this->_($message); + $this->erreur["statut"] = 'erreur'; + $this->erreur["erreur"] = $this->_($message); } - + public function hasErreur() { return isset($this->erreur["statut"]) && ('erreur' == $this->erreur["statut"]); } @@ -78,25 +81,23 @@ class Class_MoteurRecherche { public function visitExpression($expression,$pertinence,$tri) { // Analyse de l'expression $expression = trim($expression); - if ($expression == '*') { + if ($expression == '*') return; - } // Recherche par isbn (1 seul mot et isbn ou ean valide) $recherche = ''; $against_titre = ''; if (!$mode_isbn = $this->createReqForIsbn($expression)) { $mots = $this->ix->getMots($expression); - foreach ($mots as $mot) - { - $against_titre.=" ".$mot; - $mot = $this->ix->getExpressionRecherche($mot); - if ($mot) { - $this->nb_mots++; - if ($recherche !='') - $recherche .= ' '; - $recherche .= ($pertinence ? ' ' : '+') . $mot; - } + foreach ($mots as $mot) { + $against_titre .= ' ' . $mot; + if (!$mot = $this->ix->getExpressionRecherche($mot)) + continue; + + $this->nb_mots++; + if ($recherche !='') + $recherche .= ' '; + $recherche .= ($pertinence ? ' ' : '+') . $mot; } $recherche = trim($recherche); @@ -105,57 +106,54 @@ class Class_MoteurRecherche { $this->setErreur(("Il n'y aucun mot assez significatif pour la recherche")); return ; } - - if ($pertinence == true) - $against=" AGAINST('".$recherche."')"; - else - $against=" AGAINST('".$recherche."' IN BOOLEAN MODE)"; - - $this->setCondition("MATCH(titres,auteurs,editeur,collection,matieres,dewey)".$against); + + $against = " AGAINST('".$recherche."'" . ($pertinence ? '' : ' IN BOOLEAN MODE') . ')'; + + $this->setCondition('MATCH(titres, auteurs, editeur, collection, matieres, dewey)' . $against); } - if (! ($tri and $tri!="*" and !$pertinence or $mode_isbn==true)) { - //$filtre_against=str_replace("+"," ",$against); - //$filtre_against=str_replace("IN BOOLEAN MODE","",$filtre_against); - $this->select_notices="id_notice,MATCH(alpha_titre) AGAINST('".$against_titre."') as rel1, "; - $this->select_notices.="MATCH(alpha_auteur) AGAINST('".$against_titre."') as rel2 "; - $this->select_notices.="from notices "; - //$this->order_by=" order by (rel1 * 1.5)+(rel2) desc"; - $this->order_by=" order by (rel1 * 1.5)+(rel2) desc"; + if (!($tri and $tri != '*' and !$pertinence or $mode_isbn)) { + $this->select_notices = 'id_notice, ' + . "MATCH(alpha_titre) AGAINST('" . $against_titre . "') as rel1, " + . "MATCH(alpha_auteur) AGAINST('" . $against_titre . "') as rel2 " + . 'from notices '; + $this->order_by = ' order by (rel1 * 1.5) + (rel2) desc'; } } - + public function setCondition($condition) { - if ($this->conditions <> '') - $this->conditions.=' and '; + if ($this->conditions != '') + $this->conditions .= ' and '; $this->conditions .= $condition; } - public function visitAnneeDebutFin($annee_debut,$annee_fin) { - if($annee_debut) $this->setCondition("annee >='".$annee_debut."'"); - if($annee_fin) $this->setCondition("annee <='".$annee_fin."'"); + public function visitAnneeDebutFin($annee_debut, $annee_fin) { + if ($annee_debut) + $this->setCondition("annee >='" . $annee_debut . "'"); + if ($annee_fin) + $this->setCondition("annee <='" . $annee_fin . "'"); } public function visitCoteDebutFin($cote_debut, $cote_fin) { - if ($cote_debut) + if ($cote_debut) $this->setCondition(" cote >='" . strtoupper($cote_debut) . "'"); - if ($cote_fin) + if ($cote_fin) $this->setCondition(" cote <= '". strtoupper($cote_fin) . "'"); } public function visitTypeDoc($type_doc) { - $this->setCondition(" type_doc in(".$type_doc.")"); + $this->setCondition(" type_doc in(" . $type_doc . ")"); } public function visitSection($section) { - $this->visitFacette('S'.$section); + $this->visitFacette('S' . $section); } @@ -165,36 +163,42 @@ class Class_MoteurRecherche { public function visitFiltre($filtre) { - $this->all_facettes .= ' +('.implode(' ', $filtre).') '; + $this->all_facettes .= ' +(' . implode(' ', $filtre) . ') '; } public function visitClesNotices($cles_notices) { + $keys = []; foreach($cles_notices as $notice) { - if(!trim($notice)) continue; - if(isset($in_sql)) $in_sql .=","; else $in_sql = ''; - $in_sql.="'".$notice."'"; + if (!trim($notice)) + continue; + $keys[] = "'" . $notice . "'"; } - $this->setCondition("notices.clef_alpha in(".$in_sql.")"); + + $this->setCondition("notices.clef_alpha in(" . implode(', ', $keys) . ")"); } public function visitMatiere($matiere_id) { if (!$matiere = Class_Matiere::getLoader()->find($matiere_id)) continue; - + if ('' != ($sous_vedettes = trim($matiere->getSousVedettes()))) $valeur .= str_replace(' ', ' M', ' ' . $sous_vedettes); } - + public function visitAnnexe($annexe) { $this->all_facettes .= ' +Y'.$annexe; } public function visitNouveaute($nouveaute) { - $time = $this->getTimeSource()->mktime(0, 0, 0, date('m')-$nouveaute, date('d'), date('Y')); + $time = $this->getTimeSource()->mktime(0, 0, 0, + date('m') - $nouveaute, + date('d'), + date('Y')); + $this->setCondition("date_creation >'" . date('Y-m-d', $time) . "'"); } @@ -206,108 +210,106 @@ class Class_MoteurRecherche { } - public function visitTextInput($name,$operateur,$type_recherche,$valeur,$pertinence) { - if($type_recherche == "commence") - $recherche = $this->ix->alphaMaj($valeur); - else { - $recherche=""; - $mots=$this->ix->getMots($valeur); - foreach($mots as $mot) { - $mot=$this->ix->getExpressionRecherche($mot); - if($mot) { - if($pertinence) $recherche.=" ".$mot; - else $recherche.=" +".$mot; - } - } - } + public function visitTextInput($name, $operateur, $type_recherche, $valeur, $pertinence) { + if (!$recherche = $this->_visitTextInputTermsIn($valeur, $type_recherche, $pertinence)) + return; + + if (!$operateur) + $operateur = 'and'; + + if($this->conditions) + $this->conditions .= ' ' . $operateur . ' '; + elseif(stripos($operateur, 'NOT')) + $this->conditions .= 'not '; - $recherche=trim($recherche); - if(!$recherche) return ; - if (!$operateur) $operateur='and'; - if($this->conditions) $this->conditions.=" ".$operateur." "; - elseif(striPos($operateur,"NOT")) $this->conditions.="not "; - // Type de recherche - if($type_recherche == "fulltext") - $this->conditions.="MATCH(".$name.") AGAINST('".$recherche."' IN BOOLEAN MODE)"; - else - $this->conditions.=$name." like '".$recherche."%'"; + $this->conditions .= ($type_recherche == 'fulltext') + ? "MATCH(".$name.") AGAINST('".$recherche."' IN BOOLEAN MODE)" + : $name . " like '" . $recherche . "%'"; } - function lancerRecherche($criteres_recherche) { - $this->criteres_recherche=$criteres_recherche; - - $tri = $criteres_recherche->getTri(); + protected function _visitTextInputTermsIn($value, $type, $by_relevancy) { + if ('commence' == $type) + return trim($this->ix->alphaMaj($value)); + + $terms = ''; + foreach($this->ix->getMots($value) as $term) + if ($term = $this->ix->getExpressionRecherche($term)) + $terms .= ' ' . (($by_relevancy) ? '' : '+') . $term; + + return trim($terms); + } + + + public function lancerRecherche($criteres_recherche) { + $ret = ['nb_mots' => null, + 'statut' => '', + 'nombre' => 0]; + + $this->criteres_recherche = $criteres_recherche; $this->conditions = ''; $this->all_facettes = ''; - $this->select_notices = "id_notice from notices "; + $this->select_notices = 'id_notice from notices '; $this->nb_mots = 0; - $ret = array('nb_mots' => null, - 'statut' => '', - 'nombre' => 0); - if (($tri > "") && ($tri !== '*')) - $this->order_by=" order by ".$tri; - else - $this->order_by = ''; - + $tri = $criteres_recherche->getTri(); + $this->order_by = ($tri > '' && $tri !== '*') ? ' order by ' . $tri : ''; + $criteres_recherche->acceptVisitor($this); if (!empty($this->fil_ariane)) - $ret["fil_ariane"]=$this->fil_ariane; + $ret['fil_ariane'] = $this->fil_ariane; if (!empty($this->rubriques)) - $ret["rubriques"] = $this->rubriques; + $ret['rubriques'] = $this->rubriques; if ($this->_notices_not_shown) { - $ret["statut"]="erreur"; - $ret["erreur"]=''; + $ret['statut'] = 'erreur'; + $ret['erreur'] = ''; return $ret; } if ($this->all_facettes) { - $this->setCondition("MATCH(facettes) AGAINST('".trim($this->all_facettes)."' IN BOOLEAN MODE)"); + $this->setCondition("MATCH(facettes) AGAINST('" . trim($this->all_facettes)."' IN BOOLEAN MODE)"); } - $where=''; + $where = ''; if ($this->conditions) - $where="Where ".$this->conditions; + $where = 'Where ' . $this->conditions; // Finalisation des requetes - $req_notices = "Select ".$this->select_notices.$where.$this->order_by; - $req_comptage = "Select count(*) from notices ".$where; - $req_facettes = "Select id_notice,type_doc,facettes from notices ".$where.$this->limite_facettes; - + $req_notices = 'Select ' . $this->select_notices . $where . $this->order_by; + $req_comptage = 'Select count(*) from notices ' . $where; + $req_facettes = 'Select id_notice, type_doc, facettes from notices ' . $where . $this->limite_facettes; + // Lancer les requetes - $nb=fetchOne($req_comptage); + $nb = fetchOne($req_comptage); $ret['statut'] = ''; if(!$nb && ($this->criteres_recherche->getPertinence() || $this->nb_mots <=1)) { - $ret["statut"]="erreur"; - $ret["erreur"]=$this->_("Aucun résultat trouvé"); - $this->addStatEchec(2,$criteres_recherche->getCriteres()); + $ret["statut"] = 'erreur'; + $ret["erreur"] = $this->_('Aucun résultat trouvé'); + $this->addStatEchec(2, $criteres_recherche->getCriteres()); return $ret; } - if (!$nb) { - $this->criteres_recherche->rechercheElargie(); - return $this->lancerRecherche($this->criteres_recherche); - } + if (!$nb) + return $this->lancerRecherche($this->criteres_recherche->rechercheElargie()); if (!empty($this->erreur)) { - $ret['statut']=$this->erreur['statut']; - $ret['erreur']=$this->erreur['erreur']; + $ret['statut'] = $this->erreur['statut']; + $ret['erreur'] = $this->erreur['erreur']; } - $ret["nombre"]=$nb; - $ret["req_liste"]=$req_notices; - $ret["req_facettes"]=$req_facettes; + $ret['nombre'] = $nb; + $ret['req_liste'] = $req_notices; + $ret['req_facettes'] = $req_facettes; $ret['nb_mots'] = $this->nb_mots; return $ret; } - - public function visitRubrique($indice,$fil) { + + public function visitRubrique($indice, $fil) { if ($indice=='guidee') { $rubriques_tmp=['X1','X2']; if ($thesauri = Class_CodifThesaurus::getIndices('root')) { @@ -315,42 +317,40 @@ class Class_MoteurRecherche { $rubriques_tmp[]='H'.$thesaurus->getIdThesaurus(); } } - + $this->_notices_not_shown=true; $indice=''; } else - $rubriques_tmp=$this->getRubriquesGuidees($indice); + $rubriques_tmp = $this->getRubriquesGuidees($indice); $this->all_facettes .= ' +'.$indice.'*'; $this->fil_ariane = $this->getFilAriane($fil,$indice); - + // Tableau des rubriques - if($rubriques_tmp) { - $codification = Class_Codification::getInstance(); - foreach($rubriques_tmp as $rubrique) { - $libelle=$codification->getLibelleFacette($rubrique); - $url=$this->criteres_recherche->getUrlCriteresWithFacettes(); - $url['rubrique'] = $rubrique; - $url = $this->addFilArianeInUrl($url, $this->fil_ariane['fil']); - $this->rubriques[]=["libelle" => $libelle,"url" => $url]; - } + if(!$rubriques_tmp) + return; + + $codification = Class_Codification::getInstance(); + foreach($rubriques_tmp as $rubrique) { + $libelle = $codification->getLibelleFacette($rubrique); + $url = $this->criteres_recherche->getUrlCriteresWithFacettes(); + $url['rubrique'] = $rubrique; + $url = $this->addFilArianeInUrl($url, $this->fil_ariane['fil']); + $this->rubriques[]=["libelle" => $libelle, "url" => $url]; } } - public function addFilArianeInUrl($url,$fil_ariane) { + public function addFilArianeInUrl($url, $fil_ariane) { if ($fil_ariane && !empty($fil_ariane)) $url['fil'] = $fil_ariane; - else + else unset($url['fil']); return $url; } -//------------------------------------------------------------------------------------------------------ -// recup des rubriques guidees -//------------------------------------------------------------------------------------------------------ private function getRubriquesGuidees($tag){ $rubrique=$tag[0]; $id=substr($tag,1); @@ -392,14 +392,11 @@ class Class_MoteurRecherche { if(!$liste) return $items; foreach($liste as $thesaurus) $items[]="H".$thesaurus->getIdThesaurus(); } - + return $items; } -// ---------------------------------------------------------------- -// Fil d'ariane pour le catalogue guidé -// ---------------------------------------------------------------- private function getFilAriane($fil,$rubrique) { $fil_ariane = []; $ret = ['rubriques' => []]; @@ -419,19 +416,16 @@ class Class_MoteurRecherche { foreach($elems as $elem) { $url_rubrique = $this->addFilArianeInUrl($url, implode(';', $fil_ariane)); - - if(!$elem) continue; + if (!$elem) + continue; $url_rubrique['rubrique'] = $elem; - $fil_ariane []= $elem; - $libelle=Class_Codification::getInstance()->getLibelleFacette($elem); - $ret["liens"][]=["libelle" => $libelle, "url" => $url_rubrique]; - - if($elem == $rubrique) break; + if ($elem == $rubrique) + break; } $ret["fil"] = implode(';', $fil_ariane); @@ -444,16 +438,13 @@ class Class_MoteurRecherche { } - function getFacettes($req,$preferences) { + public function getFacettes($req,$preferences) { return (new Class_MoteurRecherche_Facettes())->getFacettes($req,$preferences); } - - -// ---------------------------------------------------------------- -// Stats : recherches infructueuses -// ---------------------------------------------------------------- + + private function addStatEchec($type_recherche,$criteres) { - $criteres=addslashes(serialize($criteres)); + $criteres = addslashes(serialize($criteres)); sqlExecute("insert into stats_recherche_echec(type_recherche,criteres) values($type_recherche,'$criteres')"); } diff --git a/library/Class/Notice.php b/library/Class/Notice.php index 92e89458225..8b0ea4ebcb4 100644 --- a/library/Class/Notice.php +++ b/library/Class/Notice.php @@ -19,13 +19,7 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -////////////////////////////////////////////////////////////////////////////////////// -// OPAC3 : CLASSE NOTICE (Surcharge la classe Class_NoticeUnimarc) -////////////////////////////////////////////////////////////////////////////////////// - class NoticeLoader extends Storm_Model_Loader { - - public function getNoticesFromPreferences($preferences) { $requetes = Class_Catalogue::getRequetes($preferences); $notices = $this->findAll($requetes["req_liste"]); @@ -48,19 +42,15 @@ class NoticeLoader extends Storm_Model_Loader { public function getNoticeIdsByRequeteRecherche($req) { if (!$req) return []; - $req=$this->selectIdsFromRequest($req); - - return (new Storm_Cache()) - ->useImplodeExplodeSerialization() - ->memoize([$req,__CLASS__,__FUNCTION__], - function() use ($req) { - return Zend_Registry::get('sql')->fetchAllByColumn($req); - }); - } + $closure = function() use ($req) { + return Zend_Registry::get('sql')->fetchAllByColumn($req); + }; - public function selectIdsFromRequest($request) { - return "Select inner_table.id_notice from ( ".$request." ) inner_table"; + return (new Storm_Cache()) + ->useImplodeExplodeSerialization() + ->memoize([$req, __CLASS__, __FUNCTION__], + $closure); } diff --git a/library/Class/Notice/NavigationRecherche.php b/library/Class/Notice/NavigationRecherche.php index faeeea22565..6d2e1381035 100644 --- a/library/Class/Notice/NavigationRecherche.php +++ b/library/Class/Notice/NavigationRecherche.php @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with AFI-OPAC 2.0; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class Class_Notice_NavigationRecherche { @@ -49,10 +49,10 @@ class Class_Notice_NavigationRecherche { public function getCurrentNoticeIndex() { - return array_search($this->_current_notice->getId(), + return array_search($this->_current_notice->getId(), $this->getAllNoticeIds()); } - + public function getNoticeIdAtOffset($offset) { $current_notice_id = $this->_current_notice->getId(); @@ -62,14 +62,16 @@ class Class_Notice_NavigationRecherche { $new_position = $position + $offset; $all_ids = $this->getAllNoticeIds(); return isset($all_ids[$new_position]) - ? $all_ids[$new_position] + ? $all_ids[$new_position] : $current_notice_id; } public function getAllNoticeIds() { - if (!isset($this->_all_notice_ids)) { - $result = $this->_moteur_recherche->lancerRecherche($this->_criteres_recherche); + if (!isset($this->_all_notice_ids) + && ($result = $this->_moteur_recherche + ->lancerRecherche($this->_criteres_recherche)) + && isset($result['req_liste'])) { $this->_all_notice_ids = Class_Notice::getNoticeIdsByRequeteRecherche($result['req_liste']); } return $this->_all_notice_ids; diff --git a/library/ZendAfi/View/Helper/Accueil/Base.php b/library/ZendAfi/View/Helper/Accueil/Base.php index c2439541e83..ad7e49049d5 100644 --- a/library/ZendAfi/View/Helper/Accueil/Base.php +++ b/library/ZendAfi/View/Helper/Accueil/Base.php @@ -224,15 +224,16 @@ class ZendAfi_View_Helper_Accueil_Base extends ZendAfi_View_Helper_ModuleAbstrac return ''; $this->_beforeCache(); + $closure = function() { + $template = $this->getTemplate(); + $html_array = $this->getHtml(); + return $this->getBoiteFromTemplate($template, $html_array); + }; + return (new Storm_Cache()) ->setEnabled($this->shouldCacheContent()) ->disableSerialization() - ->memoize($this->getCacheKey(), function() { - $template = $this->getTemplate(); - $html_array = $this->getHtml(); - return $this->getBoiteFromTemplate($template, $html_array); - - }); + ->memoize($this->getCacheKey(), $closure); } //------------------------------------------------------------------------------------------------------ diff --git a/library/ZendAfi/View/Helper/Accueil/Kiosque.php b/library/ZendAfi/View/Helper/Accueil/Kiosque.php index 5ecbdf6cc95..1b1e4c7963a 100644 --- a/library/ZendAfi/View/Helper/Accueil/Kiosque.php +++ b/library/ZendAfi/View/Helper/Accueil/Kiosque.php @@ -251,7 +251,6 @@ class ZendAfi_View_Helper_Accueil_Kiosque extends ZendAfi_View_Helper_Accueil_Ba public function getKiosqueHtml($page = 1) { - $catalogue=new Class_Catalogue(); $this->_nombre_notices_par_page = $this->preferences['nb_notices']; $this->preferences['nb_notices'] = 0; $this->preferences['nb_analyse'] = 0; @@ -262,14 +261,17 @@ class ZendAfi_View_Helper_Accueil_Kiosque extends ZendAfi_View_Helper_Accueil_Ba if (isset($requetes['req_comptage'])) { $nombre_total_notices = Class_Notice::countBySQLSelect($requetes['req_comptage']); - $notices = Class_Notice::findAllByRequeteRecherche($requetes['req_liste'], - $this->_nombre_notices_par_page, - $page); + $notices = Class_Notice::findAllByRequeteRecherche($requetes['req_ids'], + $this->_nombre_notices_par_page, + $page); } $html = $this->renderNoticesKiosqueHtml($notices); if (!$this->isModeChrono()) - $html = $this->getPagerHtml($page, $this->_nombre_notices_par_page, $nombre_total_notices).$html; + $html = $this->getPagerHtml($page, + $this->_nombre_notices_par_page, + $nombre_total_notices) + . $html; return $html; } diff --git a/tests/application/modules/opac/controllers/RechercheControllerTest.php b/tests/application/modules/opac/controllers/RechercheControllerTest.php index ff2d78cf8c5..444d2018945 100644 --- a/tests/application/modules/opac/controllers/RechercheControllerTest.php +++ b/tests/application/modules/opac/controllers/RechercheControllerTest.php @@ -125,7 +125,7 @@ class RechercheControllerPagerTest extends RechercheControllerNoticeTestCase { $notice = $this->fixture('Class_Notice', ['id' => 34, 'clef_oeuvre' => '']); $this->onLoaderOfModel('Class_Notice') ->whenCalled('findAllByRequeteRecherche') - ->with("Select id_notice,MATCH(alpha_titre) AGAINST(' POMME') as rel1, MATCH(alpha_auteur) AGAINST(' POMME') as rel2 from notices Where MATCH(titres,auteurs,editeur,collection,matieres,dewey) AGAINST('+(POMME POMMES POM)' IN BOOLEAN MODE) and MATCH(facettes) AGAINST('+T3' IN BOOLEAN MODE) order by (rel1 * 1.5)+(rel2) desc", + ->with("Select id_notice, MATCH(alpha_titre) AGAINST(' POMME') as rel1, MATCH(alpha_auteur) AGAINST(' POMME') as rel2 from notices Where MATCH(titres, auteurs, editeur, collection, matieres, dewey) AGAINST('+(POMME POMMES POM)' IN BOOLEAN MODE) and MATCH(facettes) AGAINST('+T3' IN BOOLEAN MODE) order by (rel1 * 1.5) + (rel2) desc", 10, 1) ->answers([$notice]) @@ -134,13 +134,14 @@ class RechercheControllerPagerTest extends RechercheControllerNoticeTestCase { $mock_sql = $this->mock() ->whenCalled('fetchOne') - ->with("Select count(*) from notices Where MATCH(titres,auteurs,editeur,collection,matieres,dewey) AGAINST('+(POMME POMMES POM)' IN BOOLEAN MODE) and MATCH(facettes) AGAINST('+T3' IN BOOLEAN MODE)") + ->with("Select count(*) from notices Where MATCH(titres, auteurs, editeur, collection, matieres, dewey) AGAINST('+(POMME POMMES POM)' IN BOOLEAN MODE) and MATCH(facettes) AGAINST('+T3' IN BOOLEAN MODE)") ->answers(45) ->whenCalled('fetchAll') - ->with("Select id_notice,type_doc,facettes from notices Where MATCH(titres,auteurs,editeur,collection,matieres,dewey) AGAINST('+(POMME POMMES POM)' IN BOOLEAN MODE) and MATCH(facettes) AGAINST('+T3' IN BOOLEAN MODE) limit 15000") + ->with("Select id_notice, type_doc, facettes from notices Where MATCH(titres, auteurs, editeur, collection, matieres, dewey) AGAINST('+(POMME POMMES POM)' IN BOOLEAN MODE) and MATCH(facettes) AGAINST('+T3' IN BOOLEAN MODE) limit 15000") ->answers([]) - ; + + ->beStrict(); Zend_Registry::set('sql', $mock_sql); @@ -428,7 +429,7 @@ class RechercheControllerViewNoticeClefAlphaTest extends RechercheControllerView ->whenCalled('execute')->answers('') ->whenCalled('fetchOne')->answers(null) ->whenCalled('fetchOne') - ->with("Select count(*) from notices Where MATCH(titres,auteurs,editeur,collection,matieres,dewey) AGAINST('+(MILLENIUM MILLENIUMS MILENIUM)' IN BOOLEAN MODE)") + ->with("Select count(*) from notices Where MATCH(titres, auteurs, editeur, collection, matieres, dewey) AGAINST('+(MILLENIUM MILLENIUMS MILENIUM)' IN BOOLEAN MODE)") ->answers(7); Zend_Registry::set('sql', $mock_sql); @@ -1414,11 +1415,11 @@ class RechercheControllerWithPanierTest extends RechercheControllerNoticeTestCas Zend_Registry::set('sql', $mock_sql); $mock_sql ->whenCalled('fetchOne') - ->with("Select count(*) from notices Where notices.clef_alpha in('COMBAT ORDINAIRE','BLACKSAD')") + ->with("Select count(*) from notices Where notices.clef_alpha in('COMBAT ORDINAIRE', 'BLACKSAD')") ->answers(2) ->whenCalled('fetchAll') - ->with("Select id_notice,type_doc,facettes from notices Where notices.clef_alpha in('COMBAT ORDINAIRE','BLACKSAD') limit 15000") + ->with("Select id_notice, type_doc, facettes from notices Where notices.clef_alpha in('COMBAT ORDINAIRE', 'BLACKSAD') limit 15000") ->answers([ ['id_notice' => 1, 'type_doc' => 1, diff --git a/tests/library/Class/CatalogueTest.php b/tests/library/Class/CatalogueTest.php index 697ec421090..a845f937f79 100644 --- a/tests/library/Class/CatalogueTest.php +++ b/tests/library/Class/CatalogueTest.php @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with AFI-OPAC 2.0; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ require_once 'ModelTestCase.php'; @@ -61,7 +61,7 @@ class CatalogueTestGetRequetesPanierWithIdUserAndIdPanier extends ModelTestCase public function testRequeteFacettes() { - $this->assertEquals("select id_notice,type_doc,facettes from notices where notices.clef_alpha in('STARWARS','JAMESBOND') and url_vignette > '' and url_vignette != 'NO' LIMIT 0,3", + $this->assertEquals("select id_notice, type_doc, facettes from notices where notices.clef_alpha in('STARWARS','JAMESBOND') and url_vignette > '' and url_vignette != 'NO' LIMIT 0,3", $this->requetes['req_facettes']); } } @@ -70,9 +70,9 @@ class CatalogueTestGetRequetesPanierWithIdUserAndIdPanier extends ModelTestCase class CatalogueTestGetRequetesPanierWithIdUserAndIdPanierUsedForId extends Storm_Test_ModelTestCase { public function setUp() { parent::setUp(); - - Class_PanierNotice::newInstanceWithId(3, ['id_user' => 3, - 'id_panier' => 10, + + Class_PanierNotice::newInstanceWithId(3, ['id_user' => 3, + 'id_panier' => 10, 'notices' => ';STARWARS;JAMESBOND']); Storm_Test_ObjectWrapper::onLoaderOfModel('Class_PanierNotice') @@ -203,28 +203,28 @@ class CatalogueTestGetSelectionFacette extends ModelTestCase { /** @test */ public function withTypeAndValuesShouldReturnThemConcatened() { - $this->assertEquals(' +(A18 A78 A8 A3)', + $this->assertEquals(' +(A18 A78 A8 A3)', Class_Catalogue::getLoader()->getSelectionFacette('A', '18;78;8;3')); } /** @test */ public function withTypeAndValuesAndNoSigneShouldNotAddPlus() { - $this->assertEquals(' A18 A78 A8 A3', + $this->assertEquals(' A18 A78 A8 A3', Class_Catalogue::getLoader()->getSelectionFacette('A', '18;78;8;3', false, false)); } /** @test */ public function withDescendantShouldAddWildCard() { - $this->assertEquals(' +(A18* A78* A8* A3*)', + $this->assertEquals(' +(A18* A78* A8* A3*)', Class_Catalogue::getLoader()->getSelectionFacette('A', '18;78;8;3', true)); } /** @test */ public function withMatersShouldConcatenateThem() { - $this->assertEquals(' +(M18 M78 M8 M3)', + $this->assertEquals(' +(M18 M78 M8 M3)', Class_Catalogue::getLoader()->getSelectionFacette('M', '18;78;8;3')); } @@ -239,7 +239,7 @@ class CatalogueTestGetSelectionFacette extends ModelTestCase { ->with(array('where' => 'libelle LIKE \'Parc animalier : %\'')) ->answers(array(Class_Matiere::getLoader()->newInstanceWithId(78))); - $this->assertEquals(' +(M18 M78)', + $this->assertEquals(' +(M18 M78)', Class_Catalogue::getLoader()->getSelectionFacette('M', '18', true)); } } @@ -396,7 +396,7 @@ class CatalogueTestGetPagedNotices extends ModelTestCase { Class_Catalogue::getLoader()->loadNoticesFor($this->_catalogue, 5, 3); } - + /** @test */ public function withCatalogForAllShouldQueryOneEgalOne() { $this->_expectNoticeFindAllBy('1=1'); @@ -435,26 +435,27 @@ class CatalogueTestGetRequetesWithFacettesAndNoCatalogue extends ModelTestCase { public function setUp() { parent::setUp(); - $this->_requetes = Class_Catalogue::getLoader()->getRequetes(array('id_catalogue' => 0, - 'facettes' => 'T1, Y1')); + $this->_requetes = Class_Catalogue::getLoader() + ->getRequetes(['id_catalogue' => 0, + 'facettes' => 'T1, Y1']); } /** @test */ public function requeteListeShouldEqualsSelectStarWhereFacettesFromNotices() { - $this->assertEquals('select * from notices where MATCH(facettes) AGAINST(\' +(T1, Y1)\' IN BOOLEAN MODE) order by alpha_titre LIMIT 5000', $this->_requetes['req_liste']); + $this->assertEquals('select * from notices where MATCH(facettes) AGAINST(\' +(T1, Y1)\' IN BOOLEAN MODE) order by alpha_titre LIMIT 5000', $this->_requetes['req_liste']); } /** @test */ public function requeteComptageShouldBeSelectCount() { - $this->assertEquals('select count(*) from notices where MATCH(facettes) AGAINST(\' +(T1, Y1)\' IN BOOLEAN MODE)', $this->_requetes['req_comptage']); + $this->assertEquals('select count(*) from notices where MATCH(facettes) AGAINST(\' +(T1, Y1)\' IN BOOLEAN MODE)', $this->_requetes['req_comptage']); } /** @test */ public function requeteFacettesShouldBeSelectIdNoticeTypeDocFacet() { - $this->assertEquals('select notices.id_notice, type_doc, facettes from notices where MATCH(facettes) AGAINST(\' +(T1, Y1)\' IN BOOLEAN MODE) LIMIT 5000', $this->_requetes['req_facettes']); + $this->assertEquals('select notices.id_notice, type_doc, facettes from notices where MATCH(facettes) AGAINST(\' +(T1, Y1)\' IN BOOLEAN MODE) LIMIT 5000', $this->_requetes['req_facettes']); } } @@ -516,7 +517,7 @@ class CatalogueTestGetNoticesByPreferences extends ModelTestCase { $this->mock_sql ->whenCalled('fetchAll') - ->with("select notices.id_notice, notices.editeur, notices.annee, notices.date_creation, notices.date_maj, notices.facettes, notices.clef_oeuvre from notices order by alpha_titre LIMIT 0,25", + ->with("select notices.id_notice, notices.editeur, notices.annee, notices.date_creation, notices.date_maj, notices.facettes, notices.clef_oeuvre from notices order by alpha_titre LIMIT 0,25", false) ->answers([['id_notice' => 23, 'editeur' => 'dargaud', 'annee' => 1975, 'date_creation' => '2011-02-23', 'date_maj' => '2011-02-25', 'facettes' => '', 'clef_oeuvre' => 'JEUNE FILLE'],]) @@ -580,7 +581,7 @@ class CatalogueTestGetNoticesByPreferences extends ModelTestCase { /* this test will fail when Class_Catalogue::_default_attribute_values change */ - $this->mock_cache + $this->mock_cache ->whenCalled('load') ->with('ab95a4588a206a1b8f977d509d5cf8bc') ->answers(serialize(array('test'))) @@ -596,13 +597,13 @@ class CatalogueTestGetNoticesByPreferences extends ModelTestCase { public function getNoticesWithCachePresentButUserAdminShouldCallThem() { $account = new stdClass(); $account->username = 'AutoTest' . time(); - $account->password = md5( 'password' ); + $account->password = md5( 'password' ); $account->ID_USER = 2; $account->ROLE_LEVEL = ZendAfi_Acl_AdminControllerRoles::ADMIN_PORTAIL; $account->confirmed = true; $account->enabled = true; ZendAfi_Auth::getInstance()->getStorage()->write($account); - + Class_Users::getLoader()->newInstanceWithId($account->ID_USER)->setRoleLevel($account->ROLE_LEVEL); $notices = Class_Catalogue::getLoader()->getNoticesByPreferences(array('id_catalogue' => 666, 'aleatoire' => 1, @@ -617,11 +618,11 @@ class CatalogueParentTest extends Storm_Test_ModelTestCase { public function setUp() { parent::setUp(); $this->_histoire = Class_Catalogue::newInstanceWithId(100, [ 'libelle' => 'Histoire', - 'parent_id' => 0]); + 'parent_id' => 0]); $this->_jeux = Class_Catalogue::newInstanceWithId(600, [ 'libelle' => 'Jeux>', - 'parent_id' => 0]); + 'parent_id' => 0]); $this->_politique = Class_Catalogue::newInstanceWithId(200, [ 'libelle' => 'Politique', - 'parent_id' => 100]); + 'parent_id' => 100]); $this->_moyenage = Class_Catalogue::newInstanceWithId(300, [ 'libelle'=>'Moyen-age', 'parent_id' => 100]); Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Catalogue') @@ -651,8 +652,8 @@ class CatalogueParentTest extends Storm_Test_ModelTestCase { public function politiqueShouldHaveHistoireAsDomaineParent() { $this->assertEquals('Histoire', $this->_politique->getDomaineParent()->getLibelle()); } - - + + /** @test */ public function histoireShouldHaveSousDomainesPolitiqueEtMoyenAge() { $this->assertEquals([ $this->_politique, $this->_moyenage],$this->_histoire->getSousDomaines()); @@ -705,7 +706,7 @@ class CatalogueBuildCriteresRechercheTest extends Storm_Test_ModelTestCase { $this->_politique = Class_Catalogue::newInstanceWithId(8, [ 'libelle' => 'Politique', 'type_doc' => '1;4', - 'matiere' => '21859;21860']); + 'matiere' => '21859;21860']); $this->_dvd = Class_Matiere::newInstanceWithId(21859, [ 'libelle' => 'DVD']); $this->_cd = Class_Matiere::newInstanceWithId(21860, [ 'libelle' => 'CD']); @@ -725,7 +726,7 @@ class CatalogueBuildCriteresRechercheTest extends Storm_Test_ModelTestCase { ->whenCalled('findAllBy') ->with(['id' => 21860]) ->answers( $this->_cd) - + ->whenCalled('findAllBy') ->with([ 'where' => "libelle LIKE 'DVD : %'"] ) ->answers([ $this->_subdvd]) @@ -735,21 +736,21 @@ class CatalogueBuildCriteresRechercheTest extends Storm_Test_ModelTestCase { ->answers([]); $profil = Class_Profil::getLoader()->newInstanceWithId(26); - Class_Profil::setCurrentProfil($profil); + Class_Profil::setCurrentProfil($profil); } /** @test */ public function politiqueShouldHaveCritereTypeDocAsFiltre() { - $this->assertEquals('T1;T4;-M21859;M888;M21860;', + $this->assertEquals('T1;T4;-M21859;M888;M21860;', $this->_politique->buildCriteresRecherche(['titre' => 'des nouveautés'])['filtres']); } - + /** @test */ public function politiqueShouldHaveCriterePcdm4AsFiltre() { $this->_politique->setPcdm4('45;48'); - $this->assertEquals('T1;T4;-M21859;M888;M21860;P45*;P48*;', + $this->assertEquals('T1;T4;-M21859;M888;M21860;P45*;P48*;', $this->_politique->buildCriteresRecherche(['titre' => 'des nouveautés'])['filtres']); } @@ -758,7 +759,7 @@ class CatalogueBuildCriteresRechercheTest extends Storm_Test_ModelTestCase { public function politiqueShouldHaveCritereDeweyAsFiltre() { $this->_politique->setPcdm4(''); $this->_politique->setDewey('333;222'); - $this->assertEquals('T1;T4;-M21859;M888;M21860;D333*;D222*;', + $this->assertEquals('T1;T4;-M21859;M888;M21860;D333*;D222*;', $this->_politique->buildCriteresRecherche(['titre' => 'des nouveautés'])['filtres']); } @@ -767,7 +768,7 @@ class CatalogueBuildCriteresRechercheTest extends Storm_Test_ModelTestCase { public function politiqueShouldHaveCritereAuteurAsFiltre() { $this->_politique->setDewey(''); $this->_politique->setAuteur('321;234'); - $this->assertEquals('T1;T4;-A321;A234;M21859;M888;M21860;', + $this->assertEquals('T1;T4;-A321;A234;M21859;M888;M21860;', $this->_politique->buildCriteresRecherche(['titre' => 'des nouveautés'])['filtres']); } @@ -778,7 +779,7 @@ class CatalogueBuildCriteresRechercheTest extends Storm_Test_ModelTestCase { $this->_politique->setAuteur(''); $this->_politique->setInteret('99;23'); $this->_politique->setTags('111'); - $this->assertEquals('T1;T4;-Z111;F99;F23;M21859;M888;M21860;', + $this->assertEquals('T1;T4;-Z111;F99;F23;M21859;M888;M21860;', $this->_politique->buildCriteresRecherche(['titre' => 'des nouveautés'])['filtres']); } @@ -788,7 +789,7 @@ class CatalogueBuildCriteresRechercheTest extends Storm_Test_ModelTestCase { $this->_politique->setCoteDebut('R233.48'); $this->_politique->setCoteFin('Z888.22'); $this->_politique->setTags(''); - $this->assertEquals('T1;T4;-M21859;M888;M21860;', + $this->assertEquals('T1;T4;-M21859;M888;M21860;', $this->_politique->buildCriteresRecherche(['titre' => 'des nouveautés'])['filtres']); } } @@ -829,14 +830,14 @@ class CatalogueAddOrCreateTest extends CatalogueParentTest { $this->assertEquals('YYYY0001', $this->_histoire->saveThesaurus()->getIdThesaurus()); } - + /** @test */ public function saveCataloguePolitiqueShouldCreateThesaurus() { Class_CodifThesaurus::getLoader() ->whenCalled('findNextThesaurusChildId') ->with('YYYY0001') ->answers('YYYY00010001') - + ->whenCalled('findThesaurusForCatalogue') ->with(200) ->answers(null) @@ -854,7 +855,7 @@ class CatalogueAddOrCreateTest extends CatalogueParentTest { ->whenCalled('findNextThesaurusChildId') ->with('YYYY0001') ->answers('YYYY00010001') - + ->whenCalled('findThesaurusForCatalogue') ->answers(null); $this->assertEquals('YYYY00010001',$this->_moyenage->saveThesaurus()->getIdThesaurus()); @@ -867,7 +868,7 @@ class CatalogueAddOrCreateTest extends CatalogueParentTest { ->whenCalled('findNextThesaurusChildId') ->with('YYYY0001') ->answers('YYYY00010001') - + ->whenCalled('findThesaurusForCatalogue') ->answers(null); $this->_politique->setParentId($this->_moyenage->getId()); @@ -884,7 +885,7 @@ class CatalogueAddOrCreateTest extends CatalogueParentTest { ->whenCalled('deleteAllWithIdOrigineAndCode') ->answers(null) - + ->whenCalled('findThesaurusForCatalogue') ->with(300) ->answers(Class_CodifThesaurus::newInstanceWithId(100)->setIdThesaurus('YYYYHIST0003')) @@ -972,7 +973,7 @@ class CatalogueGetAllNoticesIdsForDomaineTest extends Storm_Test_ModelTestCase { public function queryWithNb5Page10() { $this->mock_sql ->whenCalled('fetchAll') - ->with('select id_notice from notices where MATCH(facettes) AGAINST(\' +(T1)\' IN BOOLEAN MODE) order by alpha_titre limit 50,5') + ->with('select id_notice from notices where MATCH(facettes) AGAINST(\' +(T1)\' IN BOOLEAN MODE) order by alpha_titre limit 50,5') ->answers([ ['id_notice' => 23, 'titre' => 'POTTER'], ['id_notice' => 45, 'titre' => 'POTTER2'], ]) @@ -985,7 +986,7 @@ class CatalogueGetAllNoticesIdsForDomaineTest extends Storm_Test_ModelTestCase { public function queryWithNb1Page2() { $this->mock_sql ->whenCalled('fetchAll') - ->with('select id_notice from notices where MATCH(facettes) AGAINST(\' +(T1)\' IN BOOLEAN MODE) order by alpha_titre limit 2,1') + ->with('select id_notice from notices where MATCH(facettes) AGAINST(\' +(T1)\' IN BOOLEAN MODE) order by alpha_titre limit 2,1') ->answers([]) ->beStrict(); $this->assertEquals([], $this->_catalogue->getAllNoticeIdsForDomaine(1, 2)); diff --git a/tests/library/Class/ListesNoticesTest.php b/tests/library/Class/ListesNoticesTest.php index ca29e3997f7..0127a7871b5 100644 --- a/tests/library/Class/ListesNoticesTest.php +++ b/tests/library/Class/ListesNoticesTest.php @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with AFI-OPAC 2.0; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class ListesNoticesTest extends Storm_Test_ModelTestCase { @@ -24,30 +24,23 @@ class ListesNoticesTest extends Storm_Test_ModelTestCase { public function setUp() { parent::setUp(); - - $this->mock_cache = Storm_Test_ObjectWrapper::mock(); - Storm_Cache::setDefaultZendCache($this->mock_cache); - $this->mock_cache - ->whenCalled('load')->answers(false) - ->whenCalled('save')->answers(true); - - $this->_original_sql = Zend_Registry::get('sql'); - $this->_mock_sql = $this->mock(); - Zend_Registry::set('sql', $this->_mock_sql); - - $this->_mock_sql->whenCalled('fetchAllByColumn') - ->with(Class_Notice::selectIdsFromRequest('select * from notices')) - ->answers([4,10,23 ]); + Storm_Cache::beVolatile(); + $this->_original_sql = Zend_Registry::get('sql'); + $this->_mock_sql = $this->mock() + ->whenCalled('fetchAllByColumn') + ->with('select * from notices') + ->answers([4, 10, 23]) + ->beStrict(); + Zend_Registry::set('sql', $this->_mock_sql); Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Notice') ->whenCalled('findAllBy') ->with(['id_notice' => [4, 10, 23], 'order' => 'FIELD(id_notice, 4,10,23)']) ->answers('notices'); - } @@ -59,25 +52,17 @@ class ListesNoticesTest extends Storm_Test_ModelTestCase { /** @test */ public function noticeShouldBeFetchInRightOrder() { - $this->assertEquals('notices', - Class_Notice::findAllByRequeteRecherche('select * from notices',10)); + $this->assertEquals('notices', + Class_Notice::findAllByRequeteRecherche('select * from notices', + 10)); } - + /** @test */ public function noticeIdsShouldBeCached () { - Class_Notice::findAllByRequeteRecherche('select * from notices',10); + Class_Notice::findAllByRequeteRecherche('select * from notices', 10); $this->_mock_sql->clearAllRedirections(); - - $this->mock_cache - ->whenCalled('load') - ->with(md5(serialize(['local',[Class_Notice::selectIdsFromRequest('select * from notices'),'NoticeLoader','getNoticeIdsByRequeteRecherche']]))) - ->answers($this->mock_cache->getFirstAttributeForLastCallOn('save')); - - $this->assertEquals('notices', + $this->assertEquals('notices', Class_Notice::findAllByRequeteRecherche('select * from notices',10)); - } -} - -?> \ No newline at end of file +} \ No newline at end of file diff --git a/tests/library/Class/MoteurRechercheTest.php b/tests/library/Class/MoteurRechercheTest.php index 990583835e6..50e9848c84f 100644 --- a/tests/library/Class/MoteurRechercheTest.php +++ b/tests/library/Class/MoteurRechercheTest.php @@ -16,15 +16,15 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with AFI-OPAC 2.0; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ abstract class MoteurRechercheAbstractTest extends Storm_Test_ModelTestCase { - protected + protected $mock_sql, $_original_sql, $expected_date = '2012-05-03'; - + public function setUp() { parent::setUp(); @@ -62,15 +62,34 @@ abstract class MoteurRechercheAbstractTest extends Storm_Test_ModelTestCase { ]); $profil = Class_Profil::getLoader()->newInstanceWithId(26) ->setTypeDoc('1'); - + if (isset($params['selection_annexe'])) $profil->setSelAnnexe($params['selection_annexe']); + if (isset($params['selection_bib'])) $profil->setIdSite($params['selection_bib']); + if (isset($params['selection_sections'])) $profil->setSelSection($params['selection_sections']); + Class_Profil::setCurrentProfil($profil); - + } + + + protected function listSqlWith($where, $order=null) { + return sprintf('Select id_notice from notices Where %s%s', + $where, $order ? ' order by ' . $order : ''); + } + + + protected function countSqlWith($where) { + return sprintf('Select count(*) from notices Where %s', $where); + } + + + protected function facetSqlWith($where) { + return sprintf('Select id_notice, type_doc, facettes from notices Where %s limit 15000', + $where); } } @@ -79,98 +98,121 @@ abstract class MoteurRechercheAbstractTest extends Storm_Test_ModelTestCase { class MoteurRechercheAvanceeTest extends MoteurRechercheAbstractTest { public function expectedSql() { - return [ - [['rech_auteurs' => 'Foucault', 'operateur_auteurs' => 'and', 'type_recherche' => 'fulltext', 'pertinence' => false, 'tri' => 'alpha_auteur'] , - 'req_notices' => "Select id_notice from notices Where MATCH(auteurs) AGAINST('+(FOUCAULT FOUCAULTS FOUKOLT)' IN BOOLEAN MODE) order by alpha_auteur", - 'req_comptage' => "Select count(*) from notices Where MATCH(auteurs) AGAINST('+(FOUCAULT FOUCAULTS FOUKOLT)' IN BOOLEAN MODE)", - 'req_facettes' => "Select id_notice,type_doc,facettes from notices Where MATCH(auteurs) AGAINST('+(FOUCAULT FOUCAULTS FOUKOLT)' IN BOOLEAN MODE) limit 15000" - ], - - - - [ ['rech_auteurs' => 'Bourdieu', 'operateur_auteurs' => 'and', 'type_recherche' => 'commence', 'pertinence' => true, 'tri' => 'alpha_titre'] , - 'req_notices' => "Select id_notice from notices Where auteurs like 'BOURDIEU%' order by alpha_titre", - 'req_comptage' => "Select count(*) from notices Where auteurs like 'BOURDIEU%'", - 'req_facettes' => "Select id_notice,type_doc,facettes from notices Where auteurs like 'BOURDIEU%' limit 15000" - ] , - - [ ['rech_auteurs' => 'Clastres', 'operateur_auteurs' => 'and', - 'annexe' => 'MED1', - 'selection_annexe' => 'TUN;TAP', - 'type_recherche' => 'commence', 'pertinence' => true, 'tri' => 'alpha_titre'] , - 'req_notices' => "Select id_notice from notices Where auteurs like 'CLASTRES%' and MATCH(facettes) AGAINST('+YMED1 +(YTUN YTAP)' IN BOOLEAN MODE) order by alpha_titre", - 'req_comptage' => "Select count(*) from notices Where auteurs like 'CLASTRES%' and MATCH(facettes) AGAINST('+YMED1 +(YTUN YTAP)' IN BOOLEAN MODE)", - 'req_facettes' => "Select id_notice,type_doc,facettes from notices Where auteurs like 'CLASTRES%' and MATCH(facettes) AGAINST('+YMED1 +(YTUN YTAP)' IN BOOLEAN MODE) limit 15000" - ] , - - [ ['rech_matieres' => 'Philosophie', 'operateur_matieres' => 'and not', - 'facette' => "T1", - 'annee_debut' => '1960', - 'annee_fin' => '2013', - 'nouveaute' => '12', - 'type_recherche' => 'commence', 'pertinence' => true, 'tri' => 'alpha_titre'] , - 'req_notices' => "Select id_notice from notices Where not matieres like 'PHILOSOPHIE%' and annee >='1960' and annee <='2013' and date_creation >'".$this->expected_date."' and MATCH(facettes) AGAINST('+T1' IN BOOLEAN MODE) order by alpha_titre", - - 'req_comptage' => "Select count(*) from notices Where 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' => "Select id_notice,type_doc,facettes from notices Where not matieres like 'PHILOSOPHIE%' and annee >='1960' and annee <='2013' and date_creation >'".$this->expected_date."' and MATCH(facettes) AGAINST('+T1' IN BOOLEAN MODE) limit 15000" - ] , - - - [ [ - 'rech_titres' => 'Les nouveaux chiens de garde', 'operateur_titres' => 'and', - 'rech_editeur' => 'Raisons d\'agir', 'operateur_editeur' => 'or', - 'selection_bib'=> 4, - 'nouveaute' => '3', - 'type_recherche' => 'nimportequoi', 'pertinence' => false, 'tri' => 'alpha_titre'] , - 'req_notices' => "Select id_notice from notices Where 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 >'".$this->expected_date."' and MATCH(facettes) AGAINST('+B4' IN BOOLEAN MODE) order by alpha_titre", - - 'req_comptage' => "Select count(*) from notices Where 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 >'".$this->expected_date."' and MATCH(facettes) AGAINST('+B4' IN BOOLEAN MODE)", - 'req_facettes' => "Select id_notice,type_doc,facettes from notices Where 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 >'".$this->expected_date."' and MATCH(facettes) AGAINST('+B4' IN BOOLEAN MODE) limit 15000" - ], + $list_sql = 'Select id_notice from notices Where %s order by %s'; + $count_sql = 'Select count(*) from notices Where %s'; + $facet_sql = 'Select id_notice, type_doc, facettes from notices Where %s limit 15000'; - [ ['rech_auteurs' => 'Stiegler', 'operateur_auteurs' => 'and', - 'annexe' => 'MED1', - 'facettes' => 'G23-A345', - 'selection_annexe' => 'TUN;TAP', - 'selection_sections' => '1;12;9', - 'geo_zone' => 2, - 'type_recherche' => 'commence', 'pertinence' => true, 'tri' => 'alpha_titre'] , - 'req_notices' => "Select id_notice from notices Where auteurs like 'STIEGLER%' and MATCH(facettes) AGAINST('+YMED1 +G23 +A345 +(YTUN YTAP) +(S1 S12 S9) +(B3 B4)' IN BOOLEAN MODE) order by alpha_titre", - 'req_comptage' => "Select count(*) from notices Where auteurs like 'STIEGLER%' and MATCH(facettes) AGAINST('+YMED1 +G23 +A345 +(YTUN YTAP) +(S1 S12 S9) +(B3 B4)' IN BOOLEAN MODE)", - 'req_facettes' => "Select id_notice,type_doc,facettes from notices Where auteurs like 'STIEGLER%' and MATCH(facettes) AGAINST('+YMED1 +G23 +A345 +(YTUN YTAP) +(S1 S12 S9) +(B3 B4)' IN BOOLEAN MODE) limit 15000" - ] , - - [ ['rech_titres' => 'Les décisions absurdes', 'operateur_auteurs' => 'and', - 'annexe' => 'MED1', - 'facettes' => 'M4669', - 'selection_annexe' => 'TUN;TAP', - 'section' => 1, - 'geo_zone' => 2, - 'type_recherche' => 'commence', 'pertinence' => true, 'tri' => 'alpha_titre'] , - 'req_notices' => "Select id_notice from notices Where titres like 'LES DECISIONS ABSURDES%' and MATCH(facettes) AGAINST('+S1 +YMED1 +M4669 +(YTUN YTAP) +(B3 B4)' IN BOOLEAN MODE) order by alpha_titre", - 'req_comptage' => "Select count(*) from notices Where titres like 'LES DECISIONS ABSURDES%' and MATCH(facettes) AGAINST('+S1 +YMED1 +M4669 +(YTUN YTAP) +(B3 B4)' IN BOOLEAN MODE)", - 'req_facettes' => "Select id_notice,type_doc,facettes from notices Where titres like 'LES DECISIONS ABSURDES%' and MATCH(facettes) AGAINST('+S1 +YMED1 +M4669 +(YTUN YTAP) +(B3 B4)' IN BOOLEAN MODE) limit 15000" - ], - - [ ['rech_auteurs' => 'Stiegler', 'operateur_auteurs' => 'and', - 'annexe' => 'MED1', - 'facettes' => 'G23-A345', - 'selection_annexe' => 'TUN;TAP', - 'selection_sections' => '1;12;9', - 'geo_bib' => 3, - 'type_recherche' => 'commence', 'pertinence' => true, 'tri' => 'alpha_titre'] , - 'req_notices' => "Select id_notice from notices Where auteurs like 'STIEGLER%' and MATCH(facettes) AGAINST('+YMED1 +G23 +A345 +(YTUN YTAP) +(S1 S12 S9) +(B3)' IN BOOLEAN MODE) order by alpha_titre", - 'req_comptage' => "Select count(*) from notices Where auteurs like 'STIEGLER%' and MATCH(facettes) AGAINST('+YMED1 +G23 +A345 +(YTUN YTAP) +(S1 S12 S9) +(B3)' IN BOOLEAN MODE)", - 'req_facettes' => "Select id_notice,type_doc,facettes from notices Where auteurs like 'STIEGLER%' and MATCH(facettes) AGAINST('+YMED1 +G23 +A345 +(YTUN YTAP) +(S1 S12 S9) +(B3)' IN BOOLEAN MODE) limit 15000" - ], - - ]; + return [ + [['rech_auteurs' => 'Foucault', + 'operateur_auteurs' => 'and', + 'type_recherche' => 'fulltext', + 'pertinence' => false, + 'tri' => 'alpha_auteur'] , + '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)")], + + [['rech_auteurs' => 'Bourdieu', + 'operateur_auteurs' => 'and', + 'type_recherche' => 'commence', + 'pertinence' => true, + 'tri' => 'alpha_titre'] , + 'req_notices' => $this->listSqlWith("auteurs like 'BOURDIEU%'", + "alpha_titre"), + 'req_comptage' => $this->countSqlWith("auteurs like 'BOURDIEU%'"), + 'req_facettes' => $this->facetSqlWith("auteurs like 'BOURDIEU%'")], + + [['rech_auteurs' => 'Clastres', + 'operateur_auteurs' => 'and', + 'annexe' => 'MED1', + 'selection_annexe' => 'TUN;TAP', + '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)", + '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)")], + + [['rech_matieres' => 'Philosophie', + 'operateur_matieres' => 'and not', + 'facette' => "T1", + 'annee_debut' => '1960', + 'annee_fin' => '2013', + 'nouveaute' => '12', + '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)", + "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)")], + + [['rech_titres' => 'Les nouveaux chiens de garde', + 'operateur_titres' => 'and', + 'rech_editeur' => 'Raisons d\'agir', + 'operateur_editeur' => 'or', + 'selection_bib'=> 4, + 'nouveaute' => '3', + '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 >'".$this->expected_date."' 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 >'".$this->expected_date."' 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 >'".$this->expected_date."' and MATCH(facettes) AGAINST('+B4' IN BOOLEAN MODE)")], + + [['rech_auteurs' => 'Stiegler', + 'operateur_auteurs' => 'and', + 'annexe' => 'MED1', + 'facettes' => 'G23-A345', + 'selection_annexe' => 'TUN;TAP', + 'selection_sections' => '1;12;9', + 'geo_zone' => 2, + '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)", + '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)")], + + [['rech_titres' => 'Les décisions absurdes', + 'operateur_auteurs' => 'and', + 'annexe' => 'MED1', + 'facettes' => 'M4669', + 'selection_annexe' => 'TUN;TAP', + 'section' => 1, + 'geo_zone' => 2, + '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)", + '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)")], + + [['rech_auteurs' => 'Stiegler', + 'operateur_auteurs' => 'and', + 'annexe' => 'MED1', + 'facettes' => 'G23-A345', + 'selection_annexe' => 'TUN;TAP', + 'selection_sections' => '1;12;9', + 'geo_bib' => 3, + '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)", + '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)")]]; } - /** + /** * @dataProvider expectedSql - * @test + * @test */ public function lancerRechercheAvanceeShouldBe($params, $req_notices, $req_comptage ,$req_facettes) { $this->mockReqProfilAndZone($req_comptage,$params); @@ -191,91 +233,79 @@ class MoteurRechercheAvanceeTest extends MoteurRechercheAbstractTest { class MoteurRechercheSimpleTest extends MoteurRechercheAbstractTest { public function expectedSql() { - return [ + $match_axes = 'MATCH(titres, auteurs, editeur, collection, matieres, dewey)'; + $count_sql = 'Select count(*) from notices Where ' . $match_axes . ' AGAINST(%s IN BOOLEAN MODE)'; + $facet_sql = 'Select id_notice, type_doc, facettes from notices Where %s limit 15000'; + return [ [['expressionRecherche' => 'Bakounine'], 'nb_mots' => 1, - 'req_comptage' => "Select count(*) from notices Where MATCH(titres,auteurs,editeur,collection,matieres,dewey) AGAINST('+(BAKOUNINE BAKOUNINES BAKOUNIN)' IN BOOLEAN MODE)", - 'req_liste' => "Select id_notice,MATCH(alpha_titre) AGAINST(' BAKOUNINE') as rel1, MATCH(alpha_auteur) AGAINST(' BAKOUNINE') as rel2 from notices Where MATCH(titres,auteurs,editeur,collection,matieres,dewey) AGAINST('+(BAKOUNINE BAKOUNINES BAKOUNIN)' IN BOOLEAN MODE) order by (rel1 * 1.5)+(rel2) desc", - - 'req_facettes' => "Select id_notice,type_doc,facettes from notices Where MATCH(titres,auteurs,editeur,collection,matieres,dewey) AGAINST('+(BAKOUNINE BAKOUNINES BAKOUNIN)' IN BOOLEAN MODE) limit 15000" - ], - - [ ['expressionRecherche' => 'Slavoj Zizek', 'tri' => 'alpha_titre'] , - 'nb_mots' => 2, - 'req_comptage' => "Select count(*) from notices Where MATCH(titres,auteurs,editeur,collection,matieres,dewey) AGAINST('+(SLAVOJ SLAVOJS SLAVOJ) +(ZIZEK ZIZEKS ZIZEK)' IN BOOLEAN MODE)", - 'req_liste' => "Select id_notice from notices Where MATCH(titres,auteurs,editeur,collection,matieres,dewey) AGAINST('+(SLAVOJ SLAVOJS SLAVOJ) +(ZIZEK ZIZEKS ZIZEK)' IN BOOLEAN MODE) order by alpha_titre", - 'req_facettes' => "Select id_notice,type_doc,facettes from notices Where MATCH(titres,auteurs,editeur,collection,matieres,dewey) AGAINST('+(SLAVOJ SLAVOJS SLAVOJ) +(ZIZEK ZIZEKS ZIZEK)' IN BOOLEAN MODE) limit 15000" - - ] , - - [ ['expressionRecherche' => 'La commune de Paris', - 'annexe' => 'MED1', - 'selection_annexe' => 'TUN;TAP', - 'tri' => 'alpha_titre'] , - 'nb_mots' => 2, - 'req_comptage' => "Select count(*) from notices Where MATCH(titres,auteurs,editeur,collection,matieres,dewey) AGAINST('+(COMMUNE COMMUNES KOMUN) +(PARI PARIS PARI)' IN BOOLEAN MODE) and MATCH(facettes) AGAINST('+YMED1 +(YTUN YTAP)' IN BOOLEAN MODE)", - 'req_liste' => "Select id_notice from notices Where MATCH(titres,auteurs,editeur,collection,matieres,dewey) AGAINST('+(COMMUNE COMMUNES KOMUN) +(PARI PARIS PARI)' IN BOOLEAN MODE) and MATCH(facettes) AGAINST('+YMED1 +(YTUN YTAP)' IN BOOLEAN MODE) order by alpha_titre", - 'req_facettes' => "Select id_notice,type_doc,facettes from notices Where MATCH(titres,auteurs,editeur,collection,matieres,dewey) AGAINST('+(COMMUNE COMMUNES KOMUN) +(PARI PARIS PARI)' IN BOOLEAN MODE) and MATCH(facettes) AGAINST('+YMED1 +(YTUN YTAP)' IN BOOLEAN MODE) limit 15000" - ] , - - [ ['expressionRecherche' => '2-7427-3315-9', - 'geo_zone' => 2, - 'tri' => 'alpha_auteur'] , - 'nb_mots'=> null, - 'req_comptage' => "Select count(*) from notices Where (isbn='2-7427-3315-9' or isbn='978-2-7427-3315-6') and MATCH(facettes) AGAINST('+(B3 B4)' IN BOOLEAN MODE)", - 'req_liste' => "Select id_notice from notices Where (isbn='2-7427-3315-9' or isbn='978-2-7427-3315-6') and MATCH(facettes) AGAINST('+(B3 B4)' IN BOOLEAN MODE) order by alpha_auteur", - 'req_facettes' => "Select id_notice,type_doc,facettes from notices Where (isbn='2-7427-3315-9' or isbn='978-2-7427-3315-6') and MATCH(facettes) AGAINST('+(B3 B4)' IN BOOLEAN MODE) limit 15000" - - ] , - - [ ['expressionRecherche' => '2-7427-3315-9', - 'geo_bib' => 3, - 'tri' => 'alpha_auteur'] , - 'nb_mots'=> null, - 'req_comptage' => "Select count(*) from notices Where (isbn='2-7427-3315-9' or isbn='978-2-7427-3315-6') and MATCH(facettes) AGAINST('+(B3)' IN BOOLEAN MODE)", - 'req_liste' => "Select id_notice from notices Where (isbn='2-7427-3315-9' or isbn='978-2-7427-3315-6') and MATCH(facettes) AGAINST('+(B3)' IN BOOLEAN MODE) order by alpha_auteur", - 'req_facettes' => "Select id_notice,type_doc,facettes from notices Where (isbn='2-7427-3315-9' or isbn='978-2-7427-3315-6') and MATCH(facettes) AGAINST('+(B3)' IN BOOLEAN MODE) limit 15000" - ] , - - - [ [ 'expressionRecherche' => '9782742761579' ] , - 'nb_mots'=> null, - 'req_comptage' => "Select count(*) from notices Where (isbn='2-7427-6157-8' or isbn='978-2-7427-6157-9')", - 'req_liste' => "Select id_notice from notices Where (isbn='2-7427-6157-8' or isbn='978-2-7427-6157-9')", - 'req_facettes' => "Select id_notice,type_doc,facettes from notices Where (isbn='2-7427-6157-8' or isbn='978-2-7427-6157-9') limit 15000" - ], - - - [ [ 'expressionRecherche' => '9782742761579', 'selection_bib'=> 1 ] , - 'nb_mots'=> null, - 'req_comptage' => "Select count(*) from notices Where (isbn='2-7427-6157-8' or isbn='978-2-7427-6157-9') and MATCH(facettes) AGAINST('+B1' IN BOOLEAN MODE)", - 'req_liste' => "Select id_notice from notices Where (isbn='2-7427-6157-8' or isbn='978-2-7427-6157-9') and MATCH(facettes) AGAINST('+B1' IN BOOLEAN MODE)", - 'req_facettes' => "Select id_notice,type_doc,facettes from notices Where (isbn='2-7427-6157-8' or isbn='978-2-7427-6157-9') and MATCH(facettes) AGAINST('+B1' IN BOOLEAN MODE) limit 15000" - ], - - - [ ['expressionRecherche' => 'logo', - - 'annexe' => 'MED1', - 'facettes' => 'M52291-A15067', - 'selection_annexe' => 'TUN;TAP', - 'selection_sections' => '1;12;9' - ] , - 'nb_mots'=> 1, - 'req_comptage' => "Select count(*) from notices Where MATCH(titres,auteurs,editeur,collection,matieres,dewey) AGAINST('+(LOGO LOGOS LOGO)' IN BOOLEAN MODE) and MATCH(facettes) AGAINST('+YMED1 +M52291 +A15067 +(YTUN YTAP) +(S1 S12 S9)' IN BOOLEAN MODE)", - 'req_liste' => "Select id_notice,MATCH(alpha_titre) AGAINST(' LOGO') as rel1, MATCH(alpha_auteur) AGAINST(' LOGO') as rel2 from notices Where MATCH(titres,auteurs,editeur,collection,matieres,dewey) AGAINST('+(LOGO LOGOS LOGO)' IN BOOLEAN MODE) and MATCH(facettes) AGAINST('+YMED1 +M52291 +A15067 +(YTUN YTAP) +(S1 S12 S9)' IN BOOLEAN MODE) order by (rel1 * 1.5)+(rel2) desc", - 'req_facettes' => "Select id_notice,type_doc,facettes from notices Where MATCH(titres,auteurs,editeur,collection,matieres,dewey) AGAINST('+(LOGO LOGOS LOGO)' IN BOOLEAN MODE) and MATCH(facettes) AGAINST('+YMED1 +M52291 +A15067 +(YTUN YTAP) +(S1 S12 S9)' IN BOOLEAN MODE) limit 15000" - ] - ]; + 'req_comptage' => sprintf($count_sql, "'+(BAKOUNINE BAKOUNINES BAKOUNIN)'"), + 'req_liste' => "Select id_notice, MATCH(alpha_titre) AGAINST(' BAKOUNINE') as rel1, MATCH(alpha_auteur) AGAINST(' BAKOUNINE') as rel2 from notices Where ". $match_axes ." AGAINST('+(BAKOUNINE BAKOUNINES BAKOUNIN)' IN BOOLEAN MODE) order by (rel1 * 1.5) + (rel2) desc", + 'req_facettes' => sprintf($facet_sql, $match_axes ." AGAINST('+(BAKOUNINE BAKOUNINES BAKOUNIN)' IN BOOLEAN MODE)")], + + [['expressionRecherche' => 'Slavoj Zizek', + 'tri' => 'alpha_titre'] , + 'nb_mots' => 2, + 'req_comptage' => sprintf($count_sql, "'+(SLAVOJ SLAVOJS SLAVOJ) +(ZIZEK ZIZEKS ZIZEK)'"), + 'req_liste' => "Select id_notice from notices Where " . $match_axes . " AGAINST('+(SLAVOJ SLAVOJS SLAVOJ) +(ZIZEK ZIZEKS ZIZEK)' IN BOOLEAN MODE) order by alpha_titre", + 'req_facettes' => sprintf($facet_sql, $match_axes . " AGAINST('+(SLAVOJ SLAVOJS SLAVOJ) +(ZIZEK ZIZEKS ZIZEK)' IN BOOLEAN MODE)")], + + [['expressionRecherche' => 'La commune de Paris', + 'annexe' => 'MED1', + 'selection_annexe' => 'TUN;TAP', + 'tri' => 'alpha_titre'] , + 'nb_mots' => 2, + 'req_comptage' => sprintf($count_sql, "'+(COMMUNE COMMUNES KOMUN) +(PARI PARIS PARI)' IN BOOLEAN MODE) and MATCH(facettes) AGAINST('+YMED1 +(YTUN YTAP)'"), + 'req_liste' => "Select id_notice from notices Where " . $match_axes . " AGAINST('+(COMMUNE COMMUNES KOMUN) +(PARI PARIS PARI)' IN BOOLEAN MODE) and MATCH(facettes) AGAINST('+YMED1 +(YTUN YTAP)' IN BOOLEAN MODE) order by alpha_titre", + 'req_facettes' => sprintf($facet_sql, $match_axes . " AGAINST('+(COMMUNE COMMUNES KOMUN) +(PARI PARIS PARI)' IN BOOLEAN MODE) and MATCH(facettes) AGAINST('+YMED1 +(YTUN YTAP)' IN BOOLEAN MODE)")], + + [['expressionRecherche' => '2-7427-3315-9', + 'geo_zone' => 2, + 'tri' => 'alpha_auteur'] , + 'nb_mots'=> null, + 'req_comptage' => "Select count(*) from notices Where (isbn='2-7427-3315-9' or isbn='978-2-7427-3315-6') and MATCH(facettes) AGAINST('+(B3 B4)' IN BOOLEAN MODE)", + 'req_liste' => "Select id_notice from notices Where (isbn='2-7427-3315-9' or isbn='978-2-7427-3315-6') and MATCH(facettes) AGAINST('+(B3 B4)' IN BOOLEAN MODE) order by alpha_auteur", + 'req_facettes' => "Select id_notice, type_doc, facettes from notices Where (isbn='2-7427-3315-9' or isbn='978-2-7427-3315-6') and MATCH(facettes) AGAINST('+(B3 B4)' IN BOOLEAN MODE) limit 15000"], + + [['expressionRecherche' => '2-7427-3315-9', + 'geo_bib' => 3, + 'tri' => 'alpha_auteur'] , + 'nb_mots'=> null, + 'req_comptage' => "Select count(*) from notices Where (isbn='2-7427-3315-9' or isbn='978-2-7427-3315-6') and MATCH(facettes) AGAINST('+(B3)' IN BOOLEAN MODE)", + 'req_liste' => "Select id_notice from notices Where (isbn='2-7427-3315-9' or isbn='978-2-7427-3315-6') and MATCH(facettes) AGAINST('+(B3)' IN BOOLEAN MODE) order by alpha_auteur", + 'req_facettes' => "Select id_notice, type_doc, facettes from notices Where (isbn='2-7427-3315-9' or isbn='978-2-7427-3315-6') and MATCH(facettes) AGAINST('+(B3)' IN BOOLEAN MODE) limit 15000"] , + + [['expressionRecherche' => '9782742761579'], + 'nb_mots'=> null, + 'req_comptage' => "Select count(*) from notices Where (isbn='2-7427-6157-8' or isbn='978-2-7427-6157-9')", + 'req_liste' => "Select id_notice from notices Where (isbn='2-7427-6157-8' or isbn='978-2-7427-6157-9')", + 'req_facettes' => "Select id_notice, type_doc, facettes from notices Where (isbn='2-7427-6157-8' or isbn='978-2-7427-6157-9') limit 15000"], + + [['expressionRecherche' => '9782742761579', + 'selection_bib'=> 1], + 'nb_mots'=> null, + 'req_comptage' => "Select count(*) from notices Where (isbn='2-7427-6157-8' or isbn='978-2-7427-6157-9') and MATCH(facettes) AGAINST('+B1' IN BOOLEAN MODE)", + 'req_liste' => "Select id_notice from notices Where (isbn='2-7427-6157-8' or isbn='978-2-7427-6157-9') and MATCH(facettes) AGAINST('+B1' IN BOOLEAN MODE)", + 'req_facettes' => "Select id_notice, type_doc, facettes from notices Where (isbn='2-7427-6157-8' or isbn='978-2-7427-6157-9') and MATCH(facettes) AGAINST('+B1' IN BOOLEAN MODE) limit 15000"], + + [['expressionRecherche' => 'logo', + 'annexe' => 'MED1', + 'facettes' => 'M52291-A15067', + 'selection_annexe' => 'TUN;TAP', + 'selection_sections' => '1;12;9'], + 'nb_mots'=> 1, + 'req_comptage' => sprintf($count_sql, "'+(LOGO LOGOS LOGO)' IN BOOLEAN MODE) and MATCH(facettes) AGAINST('+YMED1 +M52291 +A15067 +(YTUN YTAP) +(S1 S12 S9)'"), + 'req_liste' => "Select id_notice, MATCH(alpha_titre) AGAINST(' LOGO') as rel1, MATCH(alpha_auteur) AGAINST(' LOGO') as rel2 from notices Where " . $match_axes . " AGAINST('+(LOGO LOGOS LOGO)' IN BOOLEAN MODE) and MATCH(facettes) AGAINST('+YMED1 +M52291 +A15067 +(YTUN YTAP) +(S1 S12 S9)' IN BOOLEAN MODE) order by (rel1 * 1.5) + (rel2) desc", + 'req_facettes' => sprintf($facet_sql, $match_axes . " AGAINST('+(LOGO LOGOS LOGO)' IN BOOLEAN MODE) and MATCH(facettes) AGAINST('+YMED1 +M52291 +A15067 +(YTUN YTAP) +(S1 S12 S9)' IN BOOLEAN MODE)")]]; } - /** + /** * @dataProvider expectedSql - * @test + * @test */ public function lancerRechercheSimpleShouldBe($params, $nb_mots,$req_comptage ,$req_notices ,$req_facettes) { - $this->mockReqProfilAndZone($req_comptage,$params); + $this->mockReqProfilAndZone($req_comptage,$params); $this->criteres_recherche->setParams($params); $retour = $this->moteur_recherche->lancerRecherche( $this->criteres_recherche); $this->assertEquals(['nombre' => 10, @@ -292,27 +322,22 @@ class MoteurRechercheSimpleTest extends MoteurRechercheAbstractTest { class MoteurRechercheSerieTest extends MoteurRechercheAbstractTest { public function expectedSql() { - return [ - [ - ['expressionRecherche' => 'Geo', - 'serie'=> 'GEO', - 'tri' => 'date_creation desc'], - - 'req_comptage' =>'Select count(*) from notices Where clef_chapeau="GEO" ', - 'req_liste' => 'Select id_notice from notices Where clef_chapeau="GEO" order by tome_alpha desc', - - 'req_facettes' => 'Select id_notice,type_doc,facettes from notices Where clef_chapeau="GEO" limit 15000' - ], - ]; + return [ + [['expressionRecherche' => 'Geo', + 'serie'=> 'GEO', + 'tri' => 'date_creation desc'], + 'req_comptage' =>'Select count(*) from notices Where clef_chapeau="GEO" ', + 'req_liste' => 'Select id_notice from notices Where clef_chapeau="GEO" order by tome_alpha desc', + 'req_facettes' => 'Select id_notice, type_doc, facettes from notices Where clef_chapeau="GEO" limit 15000']]; } - /** + /** * @dataProvider expectedSql - * @test + * @test */ public function lancerRechercheSerieShouldBe($params, $req_comptage ,$req_notices ,$req_facettes) { - $this->mockReqProfilAndZone($req_comptage,$params); + $this->mockReqProfilAndZone($req_comptage,$params); $this->criteres_recherche->setParams($params); $retour = $this->moteur_recherche->lancerRecherche($this->criteres_recherche); $this->assertEquals(['nombre' => 10, @@ -322,136 +347,109 @@ class MoteurRechercheSerieTest extends MoteurRechercheAbstractTest { 'req_facettes' => $req_facettes], $retour); } - } -class MoteurRechercheRebondTest extends MoteurRechercheAbstractTest { - public function expectedSql() { - return [ - [ - ['expressionRecherche' => 'pomme', - 'code_rebond'=> 'A774'], - 'req_comptage' =>"Select count(*) from notices Where MATCH(facettes) AGAINST('+A774' IN BOOLEAN MODE)", - 'req_liste' => "Select id_notice from notices Where MATCH(facettes) AGAINST('+A774' IN BOOLEAN MODE)", - - 'req_facettes' => "Select id_notice,type_doc,facettes from notices Where MATCH(facettes) AGAINST('+A774' IN BOOLEAN MODE) limit 15000" - ], - - - - [ - ['expressionRecherche' => 'pomme', - 'code_rebond'=> 'A774', - 'id_catalogue' => 5, - 'id_panier' => 4], - - 'req_comptage' =>"Select count(*) from notices Where MATCH(facettes) AGAINST('+A774' IN BOOLEAN MODE)", - 'req_liste' => "Select id_notice from notices Where MATCH(facettes) AGAINST('+A774' IN BOOLEAN MODE)", - - 'req_facettes' => "Select id_notice,type_doc,facettes from notices Where MATCH(facettes) AGAINST('+A774' IN BOOLEAN MODE) limit 15000" - ], - [ ['expressionRecherche' => 'Tom Cora', - 'tri' => 'alpha_titre', - 'code_rebond' => 'A888', - 'geo_zone' => 2] , - 'req_comptage' => "Select count(*) from notices Where MATCH(facettes) AGAINST('+A888 +(B3 B4)' IN BOOLEAN MODE)", - 'req_liste' => "Select id_notice from notices Where MATCH(facettes) AGAINST('+A888 +(B3 B4)' IN BOOLEAN MODE) order by alpha_titre", - 'req_facettes' => "Select id_notice,type_doc,facettes from notices Where MATCH(facettes) AGAINST('+A888 +(B3 B4)' IN BOOLEAN MODE) limit 15000" - ] , - - - [ ['expressionRecherche' => 'Tom Cora', - 'tri' => 'alpha_titre', - 'code_rebond' => 'A888', - 'geo_bib' => 3] , - 'req_comptage' => "Select count(*) from notices Where MATCH(facettes) AGAINST('+A888 +(B3)' IN BOOLEAN MODE)", - 'req_liste' => "Select id_notice from notices Where MATCH(facettes) AGAINST('+A888 +(B3)' IN BOOLEAN MODE) order by alpha_titre", - 'req_facettes' => "Select id_notice,type_doc,facettes from notices Where MATCH(facettes) AGAINST('+A888 +(B3)' IN BOOLEAN MODE) limit 15000" - ] , - - - [ ['rech_auteurs' => 'Fred Frith', - 'tri' => 'alpha_titre', - 'code_rebond' => 'A888', - 'annexe' => 'MEDIAT', - 'type_doc' => '1' - ] , - - 'req_comptage' => "Select count(*) from notices Where MATCH(facettes) AGAINST('+A888' IN BOOLEAN MODE)", - 'req_liste' => "Select id_notice from notices Where MATCH(facettes) AGAINST('+A888' IN BOOLEAN MODE) order by alpha_titre", - 'req_facettes' => "Select id_notice,type_doc,facettes from notices Where MATCH(facettes) AGAINST('+A888' IN BOOLEAN MODE) limit 15000" - - ] , - - [ ['rech_auteurs' => 'The Ex', - 'operateur_auteurs' => 'or', - 'code_rebond' => 'A111', - 'selection_annexe' => 'TUN;TAP', - 'tri' => 'alpha_titre'] , - - 'req_comptage' => "Select count(*) from notices Where MATCH(facettes) AGAINST('+A111 +(YTUN YTAP)' IN BOOLEAN MODE)", - 'req_liste' => "Select id_notice from notices Where MATCH(facettes) AGAINST('+A111 +(YTUN YTAP)' IN BOOLEAN MODE) order by alpha_titre", - 'req_facettes' => "Select id_notice,type_doc,facettes from notices Where MATCH(facettes) AGAINST('+A111 +(YTUN YTAP)' IN BOOLEAN MODE) limit 15000" - ] , - - [ ['expressionRecherche' => '2-7427-3315-9', - 'code_rebond' => 'A91919', - 'tri' => 'alpha_auteur'] , - - 'req_comptage' => "Select count(*) from notices Where MATCH(facettes) AGAINST('+A91919' IN BOOLEAN MODE)", - 'req_liste' => "Select id_notice from notices Where MATCH(facettes) AGAINST('+A91919' IN BOOLEAN MODE) order by alpha_auteur", - 'req_facettes' => "Select id_notice,type_doc,facettes from notices Where MATCH(facettes) AGAINST('+A91919' IN BOOLEAN MODE) limit 15000" - - ] , - [ ['expressionRecherche' => 'Getatchew Mekurva', - 'code_rebond' => 'A92929', - 'facettes' => 'M52291-A15067', - 'selection_annexe' => 'TUN;TAP', - 'selection_sections' => '1;12;9' - ] , - - 'req_comptage' => "Select count(*) from notices Where MATCH(facettes) AGAINST('+A92929 +M52291 +A15067 +(YTUN YTAP) +(S1 S12 S9)' IN BOOLEAN MODE)", - 'req_liste' => "Select id_notice from notices Where MATCH(facettes) AGAINST('+A92929 +M52291 +A15067 +(YTUN YTAP) +(S1 S12 S9)' IN BOOLEAN MODE)", - 'req_facettes' => "Select id_notice,type_doc,facettes from notices Where MATCH(facettes) AGAINST('+A92929 +M52291 +A15067 +(YTUN YTAP) +(S1 S12 S9)' IN BOOLEAN MODE) limit 15000" - ], - - [ ['expressionRecherche' => 'Biologie et structure', - 'tri' => 'alpha_titre', - 'fil' => ';X1', - 'code_rebond' => 'A888', - 'rubrique' =>'P4', - 'selection_annexe' => ' ', - 'geo_zone' => 2] , - - 'req_comptage' => "Select count(*) from notices Where MATCH(facettes) AGAINST('+A888 +(B3 B4)' IN BOOLEAN MODE)", - 'req_liste' =>"Select id_notice from notices Where MATCH(facettes) AGAINST('+A888 +(B3 B4)' IN BOOLEAN MODE) order by alpha_titre", - 'req_facettes' => "Select id_notice,type_doc,facettes from notices Where MATCH(facettes) AGAINST('+A888 +(B3 B4)' IN BOOLEAN MODE) limit 15000" - ], - - [ ['expressionRecherche' => 'Biologie et structure', - 'tri' => 'alpha_titre', - 'fil' => ';X1', - 'code_rebond' => 'A888', - 'rubrique' =>'P4', - 'selection_annexe' => ' ', - 'geo_bib' => 3] , - - 'req_comptage' => "Select count(*) from notices Where MATCH(facettes) AGAINST('+A888 +(B3)' IN BOOLEAN MODE)", - 'req_liste' =>"Select id_notice from notices Where MATCH(facettes) AGAINST('+A888 +(B3)' IN BOOLEAN MODE) order by alpha_titre", - 'req_facettes' => "Select id_notice,type_doc,facettes from notices Where MATCH(facettes) AGAINST('+A888 +(B3)' IN BOOLEAN MODE) limit 15000" - ] - ]; +class MoteurRechercheRebondTest extends MoteurRechercheAbstractTest { + public function expectedSql() { + return [ + [['expressionRecherche' => 'pomme', + 'code_rebond'=> 'A774'], + 'req_comptage' => $this->countSqlWith("MATCH(facettes) AGAINST('+A774' IN BOOLEAN MODE)"), + 'req_liste' => $this->listSqlWith("MATCH(facettes) AGAINST('+A774' IN BOOLEAN MODE)"), + 'req_facettes' => $this->facetSqlWith("MATCH(facettes) AGAINST('+A774' IN BOOLEAN MODE)")], + + [['expressionRecherche' => 'pomme', + 'code_rebond'=> 'A774', + 'id_catalogue' => 5, + 'id_panier' => 4], + 'req_comptage' => $this->countSqlWith("MATCH(facettes) AGAINST('+A774' IN BOOLEAN MODE)"), + 'req_liste' => $this->listSqlWith("MATCH(facettes) AGAINST('+A774' IN BOOLEAN MODE)"), + 'req_facettes' => $this->facetSqlWith("MATCH(facettes) AGAINST('+A774' IN BOOLEAN MODE)")], + + [['expressionRecherche' => 'Tom Cora', + 'tri' => 'alpha_titre', + 'code_rebond' => 'A888', + 'geo_zone' => 2] , + 'req_comptage' => $this->countSqlWith("MATCH(facettes) AGAINST('+A888 +(B3 B4)' IN BOOLEAN MODE)"), + 'req_liste' => $this->listSqlWith("MATCH(facettes) AGAINST('+A888 +(B3 B4)' IN BOOLEAN MODE)", "alpha_titre"), + 'req_facettes' => $this->facetSqlWith("MATCH(facettes) AGAINST('+A888 +(B3 B4)' IN BOOLEAN MODE)")], + + + [['expressionRecherche' => 'Tom Cora', + 'tri' => 'alpha_titre', + 'code_rebond' => 'A888', + 'geo_bib' => 3] , + 'req_comptage' => $this->countSqlWith("MATCH(facettes) AGAINST('+A888 +(B3)' IN BOOLEAN MODE)"), + 'req_liste' => $this->listSqlWith("MATCH(facettes) AGAINST('+A888 +(B3)' IN BOOLEAN MODE)", "alpha_titre"), + 'req_facettes' => $this->facetSqlWith("MATCH(facettes) AGAINST('+A888 +(B3)' IN BOOLEAN MODE)")], + + + [['rech_auteurs' => 'Fred Frith', + 'tri' => 'alpha_titre', + 'code_rebond' => 'A888', + 'annexe' => 'MEDIAT', + 'type_doc' => '1'], + 'req_comptage' => $this->countSqlWith("MATCH(facettes) AGAINST('+A888' IN BOOLEAN MODE)"), + 'req_liste' => $this->listSqlWith("MATCH(facettes) AGAINST('+A888' IN BOOLEAN MODE)", "alpha_titre"), + 'req_facettes' => $this->facetSqlWith("MATCH(facettes) AGAINST('+A888' IN BOOLEAN MODE)")], + + [['rech_auteurs' => 'The Ex', + 'operateur_auteurs' => 'or', + 'code_rebond' => 'A111', + 'selection_annexe' => 'TUN;TAP', + 'tri' => 'alpha_titre'], + 'req_comptage' => $this->countSqlWith("MATCH(facettes) AGAINST('+A111 +(YTUN YTAP)' IN BOOLEAN MODE)"), + 'req_liste' => $this->listSqlWith("MATCH(facettes) AGAINST('+A111 +(YTUN YTAP)' IN BOOLEAN MODE)", "alpha_titre"), + 'req_facettes' => $this->facetSqlWith("MATCH(facettes) AGAINST('+A111 +(YTUN YTAP)' IN BOOLEAN MODE)")], + + [['expressionRecherche' => '2-7427-3315-9', + 'code_rebond' => 'A91919', + 'tri' => 'alpha_auteur'], + 'req_comptage' => $this->countSqlWith("MATCH(facettes) AGAINST('+A91919' IN BOOLEAN MODE)"), + 'req_liste' => $this->listSqlWith("MATCH(facettes) AGAINST('+A91919' IN BOOLEAN MODE)", "alpha_auteur"), + 'req_facettes' => $this->facetSqlWith("MATCH(facettes) AGAINST('+A91919' IN BOOLEAN MODE)")], + + [['expressionRecherche' => 'Getatchew Mekurva', + 'code_rebond' => 'A92929', + 'facettes' => 'M52291-A15067', + 'selection_annexe' => 'TUN;TAP', + 'selection_sections' => '1;12;9'], + 'req_comptage' => $this->countSqlWith("MATCH(facettes) AGAINST('+A92929 +M52291 +A15067 +(YTUN YTAP) +(S1 S12 S9)' IN BOOLEAN MODE)"), + 'req_liste' => $this->listSqlWith("MATCH(facettes) AGAINST('+A92929 +M52291 +A15067 +(YTUN YTAP) +(S1 S12 S9)' IN BOOLEAN MODE)"), + 'req_facettes' => $this->facetSqlWith("MATCH(facettes) AGAINST('+A92929 +M52291 +A15067 +(YTUN YTAP) +(S1 S12 S9)' IN BOOLEAN MODE)")], + + [['expressionRecherche' => 'Biologie et structure', + 'tri' => 'alpha_titre', + 'fil' => ';X1', + 'code_rebond' => 'A888', + 'rubrique' =>'P4', + 'selection_annexe' => ' ', + 'geo_zone' => 2] , + 'req_comptage' => $this->countSqlWith("MATCH(facettes) AGAINST('+A888 +(B3 B4)' IN BOOLEAN MODE)"), + 'req_liste' => $this->listSqlWith("MATCH(facettes) AGAINST('+A888 +(B3 B4)' IN BOOLEAN MODE)", "alpha_titre"), + 'req_facettes' => $this->facetSqlWith("MATCH(facettes) AGAINST('+A888 +(B3 B4)' IN BOOLEAN MODE)")], + + [['expressionRecherche' => 'Biologie et structure', + 'tri' => 'alpha_titre', + 'fil' => ';X1', + 'code_rebond' => 'A888', + 'rubrique' =>'P4', + 'selection_annexe' => ' ', + 'geo_bib' => 3] , + 'req_comptage' => $this->countSqlWith("MATCH(facettes) AGAINST('+A888 +(B3)' IN BOOLEAN MODE)"), + 'req_liste' => $this->listSqlWith("MATCH(facettes) AGAINST('+A888 +(B3)' IN BOOLEAN MODE)", "alpha_titre"), + 'req_facettes' => $this->facetSqlWith("MATCH(facettes) AGAINST('+A888 +(B3)' IN BOOLEAN MODE)")]]; } - /** + /** * @dataProvider expectedSql - * @test + * @test */ public function lancerRechercheRebondShouldBe($params, $req_comptage ,$req_notices ,$req_facettes) { - $this->mockReqProfilAndZone($req_comptage,$params); + $this->mockReqProfilAndZone($req_comptage,$params); $this->criteres_recherche->setParams($params); $retour = $this->moteur_recherche->lancerRecherche($this->criteres_recherche); $this->assertEquals(['nombre' => 10, @@ -469,48 +467,37 @@ class MoteurRechercheRebondTest extends MoteurRechercheAbstractTest { class MoteurRechercheGuideeWithOneSubCategorieTest extends MoteurRechercheAbstractTest { public function expectedSql() { return [ - [ - [ - 'rubrique' =>'D6', - 'fil' => 'X1'], - 'fil_ariane' => 'X1;D6', - 'req_comptage' =>"Select count(*) from notices Where MATCH(facettes) AGAINST('+D6*' IN BOOLEAN MODE)", - 'req_liste' =>"Select id_notice from notices Where MATCH(facettes) AGAINST('+D6*' IN BOOLEAN MODE)", - - 'req_facettes' => "Select id_notice,type_doc,facettes from notices Where MATCH(facettes) AGAINST('+D6*' IN BOOLEAN MODE) limit 15000", - 'req_allcodif' => "select * from codif_dewey where id_dewey like '6%' and LENGTH(id_dewey)=2 order by id_dewey" - ], - - [ - ['expressionRecherche' => 'La nouvelle grille', - 'fil' => 'X1', - 'facettes' => 'M52291-A15067', - 'selection_annexe' => 'TUN;TAP', - 'selection_sections' => '1;12;9', - 'rubrique' =>'D4' - ] , - 'fil_ariane' => 'X1;D4', - 'req_comptage' => "Select count(*) from notices Where MATCH(facettes) AGAINST('+D4* +M52291 +A15067 +(YTUN YTAP) +(S1 S12 S9)' IN BOOLEAN MODE)", - 'req_liste' => "Select id_notice from notices Where MATCH(facettes) AGAINST('+D4* +M52291 +A15067 +(YTUN YTAP) +(S1 S12 S9)' IN BOOLEAN MODE)", - - 'req_facettes' => "Select id_notice,type_doc,facettes from notices Where MATCH(facettes) AGAINST('+D4* +M52291 +A15067 +(YTUN YTAP) +(S1 S12 S9)' IN BOOLEAN MODE) limit 15000", - 'req_allcodif' => "select * from codif_dewey where id_dewey like '4%' and LENGTH(id_dewey)=2 order by id_dewey"//"select * from codif_pcdm4 where id_pcdm4 like '4%' and LENGTH(id_pcdm4)=2 order by id_pcdm4" - ], - - - ]; + [['rubrique' =>'D6', + 'fil' => 'X1'], + 'fil_ariane' => 'X1;D6', + 'req_comptage' => $this->countSqlWith("MATCH(facettes) AGAINST('+D6*' IN BOOLEAN MODE)"), + 'req_liste' => $this->listSqlWith("MATCH(facettes) AGAINST('+D6*' IN BOOLEAN MODE)"), + 'req_facettes' => $this->facetSqlWith("MATCH(facettes) AGAINST('+D6*' IN BOOLEAN MODE)"), + 'req_allcodif' => "select * from codif_dewey where id_dewey like '6%' and LENGTH(id_dewey)=2 order by id_dewey"], + + [['expressionRecherche' => 'La nouvelle grille', + 'fil' => 'X1', + 'facettes' => 'M52291-A15067', + 'selection_annexe' => 'TUN;TAP', + 'selection_sections' => '1;12;9', + 'rubrique' =>'D4'], + 'fil_ariane' => 'X1;D4', + 'req_comptage' => $this->countSqlWith("MATCH(facettes) AGAINST('+D4* +M52291 +A15067 +(YTUN YTAP) +(S1 S12 S9)' IN BOOLEAN MODE)"), + 'req_liste' => $this->listSqlWith("MATCH(facettes) AGAINST('+D4* +M52291 +A15067 +(YTUN YTAP) +(S1 S12 S9)' IN BOOLEAN MODE)"), + 'req_facettes' => $this->facetSqlWith("MATCH(facettes) AGAINST('+D4* +M52291 +A15067 +(YTUN YTAP) +(S1 S12 S9)' IN BOOLEAN MODE)"), + 'req_allcodif' => "select * from codif_dewey where id_dewey like '4%' and LENGTH(id_dewey)=2 order by id_dewey"]]; } - /** + /** * @dataProvider expectedSql - * @test + * @test */ public function lancerRechercheGuideeShouldBe($params,$fil_ariane, $req_comptage, $req_liste,$req_facettes,$req_allcodif) { $this->mockReqProfilAndZone($req_comptage,$params); Class_CodifDewey::newInstanceWithId($params['rubrique'][1], ['libelle' => 'un libelle']); - + $this->mock_sql ->whenCalled('fetchAll') ->with($req_allcodif) @@ -518,7 +505,7 @@ class MoteurRechercheGuideeWithOneSubCategorieTest extends MoteurRechercheAbstra ->beStrict(); $bib=''; - if (isset($params['selection_bib'])) + if (isset($params['selection_bib'])) $bib=$params['selection_bib']; @@ -533,7 +520,7 @@ class MoteurRechercheGuideeWithOneSubCategorieTest extends MoteurRechercheAbstra 'action' => 'guidee']]; $prev_url='/opac/recherche/simple'; - + $liens[]=$home_url; $prev_url= ['controller' => 'recherche', 'action' => 'simple', @@ -544,7 +531,7 @@ class MoteurRechercheGuideeWithOneSubCategorieTest extends MoteurRechercheAbstra $liens[]=['libelle' => 'DEWEY', 'url' =>$prev_url]; - + if ($params['rubrique']!='X1') { $url_rubrique =['controller' => 'recherche', 'action' => 'simple', @@ -565,11 +552,11 @@ class MoteurRechercheGuideeWithOneSubCategorieTest extends MoteurRechercheAbstra 'fil_ariane' => ['fil'=> $fil_ariane, 'rubriques' => [], 'liens' => $liens], - + 'req_liste' => $req_liste, 'req_facettes' => $req_facettes, 'statut' => ''], - + $retour); } } @@ -579,33 +566,25 @@ class MoteurRechercheGuideeWithOneSubCategorieTest extends MoteurRechercheAbstra class MoteurRechercheGuideeWithTwoSubCategorieTest extends MoteurRechercheAbstractTest { public function expectedSql() { - return - [ - [ - [ - 'facettes' => 'M123-A989', - 'bib_select'=> '1,2,3', - 'fil' => 'X2;D3', - 'rubrique' =>'D30' - ] , - - 'fil_ariane' => 'X2;D3;D30', - 'req_comptage' => "Select count(*) from notices Where MATCH(facettes) AGAINST('+D30* +M123 +A989 +(B1 B2 B3)' IN BOOLEAN MODE)", - 'req_liste' => "Select id_notice from notices Where MATCH(facettes) AGAINST('+D30* +M123 +A989 +(B1 B2 B3)' IN BOOLEAN MODE)", - - 'req_facettes' => "Select id_notice,type_doc,facettes from notices Where MATCH(facettes) AGAINST('+D30* +M123 +A989 +(B1 B2 B3)' IN BOOLEAN MODE) limit 15000", - 'req_allcodif' => "select * from codif_dewey where id_dewey like '30%' and LENGTH(id_dewey)=3 order by id_dewey" - ] - ]; + return [ + [['facettes' => 'M123-A989', + 'bib_select'=> '1,2,3', + 'fil' => 'X2;D3', + 'rubrique' =>'D30'], + 'fil_ariane' => 'X2;D3;D30', + 'req_comptage' => $this->countSqlWith("MATCH(facettes) AGAINST('+D30* +M123 +A989 +(B1 B2 B3)' IN BOOLEAN MODE)"), + 'req_liste' => $this->listSqlWith("MATCH(facettes) AGAINST('+D30* +M123 +A989 +(B1 B2 B3)' IN BOOLEAN MODE)"), + 'req_facettes' => $this->facetSqlWith("MATCH(facettes) AGAINST('+D30* +M123 +A989 +(B1 B2 B3)' IN BOOLEAN MODE)"), + 'req_allcodif' => "select * from codif_dewey where id_dewey like '30%' and LENGTH(id_dewey)=3 order by id_dewey"]]; } - - /** + + /** * @dataProvider expectedSql - * @test + * @test */ public function lancerRechercheGuideeShouldBe($params, $fil_ariane, $req_comptage, $req_liste, $req_facettes, $req_allcodif) { - $this->mockReqProfilAndZone($req_comptage,$params); + $this->mockReqProfilAndZone($req_comptage,$params); Class_CodifDewey::newInstanceWithId(3, ['libelle' => 'un libelle']); Class_CodifDewey::newInstanceWithId(30, ['libelle' => 'une sous categorie']); @@ -637,7 +616,7 @@ class MoteurRechercheGuideeWithTwoSubCategorieTest extends MoteurRechercheAbstra 'rubrique' => 'D3', 'facettes' => 'M123-A989', 'bib_select' => '1,2,3']], - + ['libelle' =>'une sous categorie', 'url' => ['controller' => 'recherche', 'action' => 'simple', @@ -645,7 +624,7 @@ class MoteurRechercheGuideeWithTwoSubCategorieTest extends MoteurRechercheAbstra 'rubrique' => 'D30', 'facettes' => 'M123-A989', 'bib_select' => '1,2,3']]]; - + $retour = $this->moteur_recherche->lancerRecherche($this->criteres_recherche); $this->assertEquals(['nombre' => 10, @@ -675,7 +654,7 @@ class MoteurRechercheCatalogueTest extends MoteurRechercheAbstractTest { $this->_politique = Class_Catalogue::newInstanceWithId(8, [ 'libelle' => 'Dernières news', 'nouveaute' => 1, 'type_doc' => '1;4' - ]); + ]); Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Catalogue') ->whenCalled('findAllBy') @@ -689,7 +668,7 @@ class MoteurRechercheCatalogueTest extends MoteurRechercheAbstractTest { $this->_parutions = Class_Catalogue::newInstanceWithId(9, [ 'libelle' => 'Dernières parutions', 'annee_debut' => '1997', 'cote_debut' => 'N222.77', - 'cote_fin' => 'V222.77']); + 'cote_fin' => 'V222.77']); Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Catalogue') ->whenCalled('findAllBy') @@ -700,14 +679,14 @@ class MoteurRechercheCatalogueTest extends MoteurRechercheAbstractTest { public function expectedSql() { return [ - [ + [ [ 'id_catalogue' => 8 ], 'req_comptage' => "Select count(*) from notices Where date_creation >'". $this->expected_date."' and MATCH(facettes) AGAINST('+(T1 T4)' IN BOOLEAN MODE)", 'req_libelle' => "select libelle from codif_dewey where id_dewey='3'", 'req_liste' => "Select id_notice from notices Where date_creation >'". $this->expected_date ."' and MATCH(facettes) AGAINST('+(T1 T4)' IN BOOLEAN MODE)", - - 'req_facettes' => "Select id_notice,type_doc,facettes from notices Where date_creation >'". $this->expected_date ."' and MATCH(facettes) AGAINST('+(T1 T4)' IN BOOLEAN MODE) limit 15000" + + 'req_facettes' => "Select id_notice, type_doc, facettes from notices Where date_creation >'". $this->expected_date ."' and MATCH(facettes) AGAINST('+(T1 T4)' IN BOOLEAN MODE) limit 15000" ], @@ -717,20 +696,20 @@ class MoteurRechercheCatalogueTest extends MoteurRechercheAbstractTest { 'req_comptage' => "Select count(*) from notices Where cote >='N222.77' and cote <= 'V222.77' and annee >='1997'", 'req_libelle' => "select libelle from codif_dewey where id_dewey='3'", 'req_liste' => "Select id_notice from notices Where cote >='N222.77' and cote <= 'V222.77' and annee >='1997'", - - 'req_facettes' => "Select id_notice,type_doc,facettes from notices Where cote >='N222.77' and cote <= 'V222.77' and annee >='1997' limit 15000" + + 'req_facettes' => "Select id_notice, type_doc, facettes from notices Where cote >='N222.77' and cote <= 'V222.77' and annee >='1997' limit 15000" ] ]; } - /** + /** * @dataProvider expectedSql - * @test + * @test */ public function lancerRechercheCatalogueWithNouveauteShouldBe($params,$req_comptage ,$req_libelle,$req_liste,$req_facettes) { - $this->mockReqProfilAndZone($req_comptage,$params); + $this->mockReqProfilAndZone($req_comptage,$params); $this->mock_sql ->whenCalled('fetchOne') ->with($req_libelle) @@ -741,19 +720,19 @@ class MoteurRechercheCatalogueTest extends MoteurRechercheAbstractTest { ->whenCalled('fetchOne') ->with( "select libelle from codif_dewey where id_dewey='30'") ->answers("une sous categorie"); - + $bib=''; - if (isset($params['selection_bib'])) + if (isset($params['selection_bib'])) $bib=$params['selection_bib']; $this->_translate = Zend_Registry::get('translate'); $this->criteres_recherche->setParams($params); - + $prev_url= ['controller' => 'recherche', 'action' => 'simple', 'rubrique' => 'X2']; $retour = $this->moteur_recherche->lancerRecherche($this->criteres_recherche); - + $this->assertEquals(['nombre' => 10, 'nb_mots' => 0, 'req_liste' => $req_liste, diff --git a/tests/library/ZendAfi/View/Helper/Accueil/KiosqueTest.php b/tests/library/ZendAfi/View/Helper/Accueil/KiosqueTest.php index 4d0dc61bacc..cf12b7466c8 100644 --- a/tests/library/ZendAfi/View/Helper/Accueil/KiosqueTest.php +++ b/tests/library/ZendAfi/View/Helper/Accueil/KiosqueTest.php @@ -250,16 +250,17 @@ abstract class ZendAfi_View_Helper_Accueil_KiosqueRequetesTestCase extends ZendA ->answers(10) ->whenCalled('fetchAllByColumn') - ->with("Select inner_table.id_notice from ( select * from notices where notices.clef_alpha in('BB') and url_vignette > '' and url_vignette != 'NO' order by date_creation DESC ) inner_table") - ->answers([ 2,45]) + ->with("select notices.id_notice from notices where notices.clef_alpha in('BB') and url_vignette > '' and url_vignette != 'NO' order by date_creation DESC ") + ->answers([2, 45]) ->beStrict(); Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Notice') ->whenCalled('findAllBy') - ->with(['id_notice' => [2,45], 'order' => 'FIELD(id_notice, 2,45)']) + ->with(['id_notice' => [2, 45], + 'order' => 'FIELD(id_notice, 2,45)']) ->answers($this->_notices); - Class_AdminVar::newInstanceWithId('CACHE_ACTIF', ['valeur'=>0 ]); + Class_AdminVar::newInstanceWithId('CACHE_ACTIF', ['valeur' => 0]); } @@ -269,7 +270,6 @@ abstract class ZendAfi_View_Helper_Accueil_KiosqueRequetesTestCase extends ZendA } - public function getPreferences() { return ['type_module' => 'KIOSQUE', 'division' => 3, @@ -327,27 +327,30 @@ class ZendAfi_View_Helper_Accueil_KiosqueRequetesAsRedacteurTest extends ZendAfi class ZendAfi_View_Helper_Accueil_KiosqueRequetesWithCacheEnabledTest extends ZendAfi_View_Helper_Accueil_KiosqueRequetesTestCase { public function setUp() { parent::setUp(); + Storm_Cache::beVolatile(); + Class_AdminVar::newInstanceWithId('CACHE_ACTIF', ['valeur' => 1]); + } - $this->mock_cache = Storm_Test_ObjectWrapper::mock(); - Storm_Cache::setDefaultZendCache($this->mock_cache); - Class_AdminVar::newInstanceWithId('CACHE_ACTIF', ['valeur'=>1]); - $this->mock_cache - ->whenCalled('load')->answers(false) - ->whenCalled('save')->answers(true); + public function tearDown() { + Storm_Cache::setDefaultZendCache(null); + parent::tearDown(); + } + /** @test */ + public function notFoundInCacheShouldDisplayIt() { $this->_html = $this->_helper->getBoite(); $this->assertXPathContentContains($this->_html, '//a', 'Harry Potter et le prisonnier d\'Azkaban'); } /** @test */ - public function findAllByRequeteRechercheQueryWithCacheEnabled() { - $this->mock_cache->whenCalled('load')->answers($this->_html); - + public function foundInCacheShouldDiplayIt() { + $this->_helper->getBoite(); + $this->_helper = new ZendAfi_View_Helper_Accueil_Kiosque(3, $this->getPreferences()); + $this->_helper->setView(new ZendAfi_Controller_Action_Helper_View()); $this->mock_sql->clearAllRedirections(); - $this->_html = $this->_helper->getBoite(); $this->assertXPathContentContains($this->_html, '//a', 'Harry Potter et le prisonnier d\'Azkaban'); } -- GitLab