From ea7f76cfc1652d668221cfb7580ad5cda1057e7c Mon Sep 17 00:00:00 2001
From: llaffont <llaffont@afi-sa.fr>
Date: Sat, 25 Jul 2015 14:48:21 +0200
Subject: [PATCH] dev #22209 search result feed

reification of Search Result
---
 .../opac/controllers/RechercheController.php  |  57 ++++----
 .../opac/views/scripts/recherche/guidee.phtml |  21 +--
 .../scripts/recherche/resultatRecherche.phtml |  60 ++++----
 .../views/scripts/recherche/simple.phtml      |  13 +-
 library/Class/MoteurRecherche.php             |  51 +++----
 library/Class/MoteurRecherche/Facettes.php    |  25 ++--
 library/Class/MoteurRecherche/Result.php      | 136 ++++++++++++++++++
 library/Class/MoteurRecherche/Resultat.php    |  35 -----
 library/Class/Notice/NavigationRecherche.php  |  13 +-
 .../View/Helper/ListeNotices/ChronoSource.php |   3 -
 .../controllers/RechercheControllerTest.php   |  66 +++++----
 11 files changed, 284 insertions(+), 196 deletions(-)
 create mode 100644 library/Class/MoteurRecherche/Result.php
 delete mode 100644 library/Class/MoteurRecherche/Resultat.php

diff --git a/application/modules/opac/controllers/RechercheController.php b/application/modules/opac/controllers/RechercheController.php
index dae20555c21..e26503fa16b 100644
--- a/application/modules/opac/controllers/RechercheController.php
+++ b/application/modules/opac/controllers/RechercheController.php
@@ -129,21 +129,20 @@ class RechercheController extends ZendAfi_Controller_Action {
               'page' => $this->_getParam('page', 1),
               'records' => []];
 
-    $ret = $this->moteur->lancerRecherche($criteres_recherche);
-    if (isset($ret['statut']) && $ret['statut'] == 'erreur') {
+    $result = $this->moteur->lancerRecherche($criteres_recherche);
+    if ($result->isError()) {
       $this->_helper->json($datas);
       return;
     }
 
-    $datas['total'] = $ret['nombre'];
+    $datas['total'] = $result->getRecordsCount();
     $records = [];
-    (new Storm_Model_Collection($this->_getListNotices($criteres_recherche, $ret['req_liste'])))
-      ->eachDo(
-               function($record) use (&$records) {
-                 $json = new Class_Notice_JsonVisitor();
-                 $record->acceptVisitor($json);
-                 $records[] = $json->data();
-               });
+    $result->recordsDo(
+                       function($record) use (&$records) {
+                         $json = new Class_Notice_JsonVisitor();
+                         $record->acceptVisitor($json);
+                         $records[] = $json->data();
+                       });
 
     $datas['records'] = $records;
     $this->_helper->json($datas);
@@ -226,42 +225,36 @@ class RechercheController extends ZendAfi_Controller_Action {
 
 
   public function renderResultatRecherche($criteres_recherche) {
-    $ret = $this->moteur->lancerRecherche($criteres_recherche);
+    $search_result = $this->moteur->lancerRecherche($criteres_recherche);
 
     $this->view->criteres_recherche = $criteres_recherche;
-    $this->view->url_facette=$this->view->url($criteres_recherche->getUrlCriteresWithFacettes(),null,true);
+    $this->view->url_facette=$this->view->url($criteres_recherche->getUrlCriteresWithFacettes(),
+                                              null,
+                                              true);
     $this->view->url_retour = $this->view->url($criteres_recherche->getUrlRetourListe());
+    $this->view->search_result = $search_result;
+    $this->view->tags = [];
+    $this->view->facettes = [];
 
-    if (isset($ret['fil_ariane']))
-      $this->view->fil_ariane = $ret['fil_ariane'];
-    if (isset($ret['rubriques']))
-      $this->view->rubriques = $ret['rubriques'];
-
-    if (isset($ret["statut"]) && $ret["statut"]=="erreur") {
-      $ret['nombre'] = 0;
-      $ret['page_cours'] = 0;
-      $this->view->liste = [];
-      $this->view->resultat = $ret;
+    if ($search_result->isError())
       return;
-    }
 
-    $this->addHistoRecherche(1,$criteres_recherche);
+    $this->addHistoRecherche(1, $criteres_recherche);
 
-    $this->view->liste = $this->_getListNotices($criteres_recherche, $ret['req_liste']);
+    $facettes_and_tags = $search_result->fetchFacetsAndTags($this->preferences);
+    $facettes = $facettes_and_tags['facettes'];
+    $tags = $facettes_and_tags['tags'];
 
-    $resultat = ['page_cours' => $this->_getParam('page'),
-                 'page_size' => $criteres_recherche->getPageSize(),
-                 'nombre' => $ret['nombre']];
-
-    $facettes = $this->moteur->getFacettes($ret["req_facettes"], $this->preferences);
     $this->view->getHelper('PageContext')->setContextHelper('Notice_FacettesTypeDoc',
-                                                            [$facettes['facettes']]);
+                                                            [$facettes]);
 
     $this->view->_current_module['preferences']['liste_format'] = $this->_getParam('liste_format',
                                                                                    $this->preferences['liste_format']);
-    $this->view->resultat = array_merge($resultat, $facettes);
+
     $this->view->is_pertinence = $criteres_recherche->getPertinence();
     $this->view->tri = $criteres_recherche->getTri();
+    $this->view->facettes = $facettes;
+    $this->view->tags = $tags;
   }
 
 
diff --git a/application/modules/opac/views/scripts/recherche/guidee.phtml b/application/modules/opac/views/scripts/recherche/guidee.phtml
index 4fbd1cc2989..60565f5cba8 100644
--- a/application/modules/opac/views/scripts/recherche/guidee.phtml
+++ b/application/modules/opac/views/scripts/recherche/guidee.phtml
@@ -1,11 +1,10 @@
-
 <?php
 
 // Fil d'ariane
-if($this->fil_ariane["liens"]) {
+$links = $this->search_result->getBreadcrumb()['liens'];
+if($links) {
   echo '<div class="fil_ariane_rech_guidee">';
-
-  foreach($this->fil_ariane["liens"] as $fil) {
+  foreach($links as $fil) {
     print('<span><a href="'.$this->url($fil["url"],null,true).'">&nbsp;&raquo;&nbsp;'.$fil["libelle"].'</a></span>');
   }
 
@@ -17,12 +16,14 @@ echo $this->tagCriteresRecherche($this->criteres_recherche);
 print('<hr>');
 
 // Rubriques
-if(!$this->rubriques)
-  print($this->_("Il n'y a plus de sous-niveau"));
-else {
-  foreach($this->rubriques as $rubrique)  {
-    print('<a href="'.$this->url($rubrique["url"],null,true).'">&raquo;&nbsp;'.$rubrique["libelle"].'</a><br>');
-  }
+if (!$rubriques = $this->search_result->getRubrics()) {
+  echo $this->_("Il n'y a plus de sous-niveau");
+  return;
 }
 
+
+foreach($rubriques as $rubrique)  {
+  echo '<a href="'.$this->url($rubrique["url"],null,true).'">&raquo;&nbsp;'.$rubrique["libelle"].'</a><br>';
+  }
+
 ?>
diff --git a/application/modules/opac/views/scripts/recherche/resultatRecherche.phtml b/application/modules/opac/views/scripts/recherche/resultatRecherche.phtml
index 043ef7eeb23..fffb9737691 100644
--- a/application/modules/opac/views/scripts/recherche/resultatRecherche.phtml
+++ b/application/modules/opac/views/scripts/recherche/resultatRecherche.phtml
@@ -1,15 +1,10 @@
 <?php
 $preferences = $this->_current_module["preferences"];
 
-$hasFacettes  = (1 == $preferences["facettes_actif"]) && $this->resultat['nombre'];
-$hasTags      = (1 == $preferences["tags_actif"]) && $this->resultat['nombre'];
+$hasFacettes  = (1 == $preferences["facettes_actif"]) && $this->search_result->getRecordsCount();
+$hasTags      = (1 == $preferences["tags_actif"]) && $this->search_result->getRecordsCount();
 $tagsPosition = $preferences["tags_position"];
 
-extract($this->resultat);
-
-if(!isset($facettes))
-  $facettes = [];
-
 $this->openBoite($this->titre);
 
 if ($this->is_pertinence) {
@@ -19,10 +14,11 @@ if ($this->is_pertinence) {
 <div class="resultats_page">
   <?php
   echo $this->tagTriRecherche($this->criteres_recherche);
-  echo $this->tagTitreEtNombreDeResultats($nombre, $this->criteres_recherche);
-  echo $this->tagNombreDePages($page_cours);
+  echo $this->tagTitreEtNombreDeResultats($this->search_result->getRecordsCount(),
+                                          $this->criteres_recherche);
+  echo $this->tagNombreDePages($this->criteres_recherche->getPage());
 
-  if ($this->rubriques || $this->fil_ariane) {
+  if ($this->search_result->getRubrics() || $this->search_result->getBreadcrumb()) {
     echo $this->render('recherche/guidee.phtml');
   } else {
     echo $this->tagCriteresRecherche($this->criteres_recherche);
@@ -41,14 +37,7 @@ if ($this->is_pertinence) {
                             sprintf('&raquo; %s',
                                     $this->_('Retour à la recherche initiale')));?>
     </span>
-    <?php if ($this->url_retour_notice) { ?>
-      <span>
-        <?php
-        echo $this->tagAnchor($this->url_retour_notice,
-                              sprintf('&raquo; %s',
-                                      $this->_('Retour à la notice'))); ?>
-      </span>
-    <?php } ?>
+
     <span>
       <?php echo $this->tagAnchor($this->url($this->criteres_recherche->getUrlNouvelleRecherche(), null, true),
                                   '&raquo; '.$this->_('Nouvelle recherche')); ?>
@@ -57,7 +46,8 @@ if ($this->is_pertinence) {
 
     <span>
       <?php if ((int)$preferences['suggestion_achat'] == 1)
-        echo $this->tagAnchor(['controller' => 'abonne', 'action' => 'suggestion-achat'],
+        echo $this->tagAnchor(['controller' => 'abonne',
+                               'action' => 'suggestion-achat'],
                               '&raquo; '.$this->_('Suggérer un achat'));?>
     </span>
   </div>
@@ -65,36 +55,40 @@ if ($this->is_pertinence) {
 </div>
 <?php
 $this->closeBoite();
-
-
-if (!isset($tags)) $tags=[];
 ?>
 
 
 <?php
-$html_liste_notices = $this->listeNotices($this->liste,
-                                          $nombre,
-                                          $page_cours,
+$html_liste_notices = $this->listeNotices($this->search_result->fetchRecords(),
+                                          $this->search_result->getRecordsCount(),
+                                          $this->criteres_recherche->getPage(),
                                           $preferences,
                                           $this->criteres_recherche);
 
-$html_pager = $this->pager($nombre,
+$html_pager = $this->pager($this->search_result->getRecordsCount(),
                            $this->criteres_recherche->getPageSize(),
-                           $page_cours,
+                           $this->criteres_recherche->getPage(),
                            array_merge($this->criteres_recherche->getUrlRetourListe(),
                                        ['controller' => 'recherche',
                                         'action' => 'simple']));
-$nuage_tags_title = $preferences["tags_message"] ? $this->tag('h2', $preferences["tags_message"]) : '';
+
+$nuage_tags_title = $preferences["tags_message"]
+                  ? $this->tag('h2', $preferences["tags_message"])
+                              : '';
 
 $html_nuage_tags = $this->tag('div',
                               $nuage_tags_title
-                             .$this->nuageTags($tags, null, $this->criteres_recherche)
-                              , ['class' => 'facette_outer nuage_outer']);
+                             . $this->nuageTags($this->tags, null, $this->criteres_recherche),
+                              ['class' => 'facette_outer nuage_outer']);
 
 $html_facettes = '<div class="facette_outer" style="margin-left:10px;margin-top:17px">'.
-                 ($preferences["facettes_message"] ? ('<h2>'.$preferences["facettes_message"].'</h2>') : '').
-$this->facettes($facettes, $preferences, $this->criteres_recherche).
-'</div>';
+                 ($preferences["facettes_message"]
+                   ? ('<h2>'.$preferences["facettes_message"].'</h2>')
+                   : '')
+                  . $this->facettes($this->facettes,
+                                    $preferences,
+                                    $this->criteres_recherche)
+                 . '</div>';
 ?>
 
 
diff --git a/application/modules/telephone/views/scripts/recherche/simple.phtml b/application/modules/telephone/views/scripts/recherche/simple.phtml
index 36f67ef800c..770cf4eea74 100644
--- a/application/modules/telephone/views/scripts/recherche/simple.phtml
+++ b/application/modules/telephone/views/scripts/recherche/simple.phtml
@@ -1,16 +1,17 @@
 <ul data-role="listview">
 <?php
 echo $this->toolbar("Recherche", $this->url(array(), null, true));
-echo $this->tagTitreEtNombreDeResultats($this->resultat['nombre'],$this->criteres_recherche);
+echo $this->tagTitreEtNombreDeResultats($this->search_result->getRecordsCount(),
+                                        $this->criteres_recherche);
 
 
-echo $this->listeNotices($this->liste,
-                         $this->resultat['nombre'],
-                         $this->resultat['page_cours'],
+echo $this->listeNotices($this->search_result->fetchRecords(),
+                         $this->search_result->getRecordsCount(),
+                         $this->criteres_recherche->getPage(),
                          $this->preferences);
 
-echo $this->pager($this->resultat['nombre'],
+echo $this->pager($this->search_result->getRecordsCount(),
                   $this->preferences["liste_nb_par_page"],
-                  $this->resultat['page_cours']);
+                  $this->criteres_recherche->getPage());
 ?>
 </ul>
diff --git a/library/Class/MoteurRecherche.php b/library/Class/MoteurRecherche.php
index 0d2f5a39a9f..33ef7eefb1d 100644
--- a/library/Class/MoteurRecherche.php
+++ b/library/Class/MoteurRecherche.php
@@ -23,7 +23,8 @@ class Class_MoteurRecherche {
 
   private $ix;                                      // Classe d'indexation
   private $limite_facettes = ' limit 15000';          // limite pour le calcul des facettes
-  protected $all_facettes,
+  protected
+    $all_facettes,
     $_notices_not_shown = false,
     $fil_ariane,
     $rubriques,
@@ -388,27 +389,20 @@ class Class_MoteurRecherche {
 
 
   public function lancerRecherche($criteres_recherche) {
-    $ret = ['nb_mots' => null,
-            'statut' => '',
-            'nombre' => 0];
-
     $this->visitSearchSettings($criteres_recherche);
 
-    if (!empty($this->fil_ariane))
-      $ret['fil_ariane'] = $this->fil_ariane;
+    $search_result = new Class_MoteurRecherche_Result($this, $criteres_recherche);
+    $search_result
+      ->setBreadcrumb($this->fil_ariane)
+      ->setRubrics($this->rubriques);
 
-    if (!empty($this->rubriques))
-      $ret['rubriques'] = $this->rubriques;
+    if ($this->_notices_not_shown)
+      return $search_result->beError();
 
-    if ($this->_notices_not_shown) {
-        $ret['statut'] = 'erreur';
-        $ret['erreur'] = '';
-        return $ret;
+    if(is_array($where = $this->buildWherePartQuery())) {
+      return $search_result->beError($where['erreur']);
     }
 
-    if(is_array($where = $this->buildWherePartQuery()))
-      return $where;
-
     // Finalisation des requetes
     $req_notices = 'Select ' .
       $this->select_notices .
@@ -424,29 +418,26 @@ class Class_MoteurRecherche {
 
     // Lancer les requetes
     $nb = fetchOne($req_comptage);
-    $ret['statut'] = '';
     if (!$nb && !$this->_shouldExtend()) {
-      $ret['statut'] = 'erreur';
-      $ret['erreur'] = $this->_('Aucun résultat trouvé');
-      $ret['req_liste'] = $req_notices;
       $this->addStatEchec(2, $criteres_recherche->getCriteres());
-      return $ret;
+
+      return $search_result
+        ->beError($this->_('Aucun résultat trouvé'))
+        ->setRecordsQuery($req_notices);
     }
 
     if (!$nb)
       return $this->lancerRecherche($this->criteres_recherche->rechercheElargie());
 
     if (!empty($this->erreur)) {
-      $ret['statut'] = $this->erreur['statut'];
-      $ret['erreur'] = $this->erreur['erreur'];
+      $search_result->beError($this->erreur['erreur']);
     }
 
-    $ret['nombre'] = $nb;
-    $ret['req_liste'] = $req_notices;
-    $ret['req_facettes'] = $req_facettes;
-    $ret['nb_mots'] = $this->nb_mots;
-
-    return $ret;
+    return $search_result
+      ->setRecordsQuery($req_notices)
+      ->setRecordsCount($nb)
+      ->setFacetsQuery($req_facettes)
+      ->setWordCount($this->nb_mots);
   }
 
 
@@ -458,6 +449,8 @@ class Class_MoteurRecherche {
 
 
   public function visitRubrique($indice, $fil) {
+    $this->rubriques = [];
+
     if ($indice=='guidee') {
       $rubriques_tmp=['X1','X2'];
       if ($thesauri = Class_CodifThesaurus::getIndices('root')) {
diff --git a/library/Class/MoteurRecherche/Facettes.php b/library/Class/MoteurRecherche/Facettes.php
index 6e165c5b047..65d68f202f0 100644
--- a/library/Class/MoteurRecherche/Facettes.php
+++ b/library/Class/MoteurRecherche/Facettes.php
@@ -34,7 +34,9 @@ class Class_MoteurRecherche_Facettes {
   }
 
   protected function _getFacettes($req,$preferences)  {
-    // Preferences
+    $result = ['facettes' => [],
+               'tags' => []];
+
     $p_facette = array("nombre" => $preferences["facettes_nombre"],
                        "actif" => $preferences["facettes_actif"],
                        "types" => "T".$preferences["facettes_codes"]);
@@ -44,22 +46,23 @@ class Class_MoteurRecherche_Facettes {
                  "types" => $preferences["tags_codes"],
                  "nombre" => $preferences["tags_nombre"]);
 
-    if(!$p_facette["actif"] and !$p_tag["actif"]) return [];
+    if(!$p_facette["actif"] and !$p_tag["actif"])
+      return $result;
 
     // Lecture des notices
     $rows = Zend_Registry::get('sql')->fetchAll($req);
     $facettes = $this->getNombreFacettesResultat($rows);
 
     // Constituer le tableau des facettes
-    $table = $this->extractFacettes($p_facette['types'], $facettes, $p_facette["nombre"]);
+    $result['facettes'] = $this->extractFacettes($p_facette['types'], $facettes, $p_facette["nombre"]);
 
     if(!$p_tag["actif"])
-      return $table;
+      return $result;
 
     // Constituer le tableau des tags
-    $table['tags'] = $this->extractTags($p_tag['types'], $p_tag['nombre'], $facettes);
+    $result['tags'] = $this->extractTags($p_tag['types'], $p_tag['nombre'], $facettes);
 
-    return $table;
+    return $result;
   }
 
 
@@ -101,7 +104,7 @@ class Class_MoteurRecherche_Facettes {
 
   public function extractFacettes($codes_facettes, $facettes, $nb_facettes) {
     $rubriques = Class_Notice_RubriqueFacette::parseRubriquesFromPreferenceField($codes_facettes);
-    $table = ['facettes' => []];
+    $table = [];
 
     foreach ($rubriques as $rubrique) {
       $rubric_code = $rubrique->getCode();
@@ -114,13 +117,13 @@ class Class_MoteurRecherche_Facettes {
                                                 ? count($this->_facettes_par_code_rubrique[$rubric_code])
                                                 : $nb_facettes));
 
-      $table["facettes"][$rubric_code]["titre"] = $rubrique->getLibelle();
+      $table[$rubric_code]["titre"] = $rubrique->getLibelle();
 
       foreach($rubric_facets as $k => $facette) {
         $nb = $k+1;
-        $table["facettes"][$rubric_code][$nb]["id"] = $cle=$facette->getCle();
-        $table["facettes"][$rubric_code][$nb]["libelle"]= $facette->getLibelleFacette();
-        $table["facettes"][$rubric_code][$nb]["nombre"]= $this->_nb_facettes_par_cle[$cle];
+        $table[$rubric_code][$nb]["id"] = $cle=$facette->getCle();
+        $table[$rubric_code][$nb]["libelle"]= $facette->getLibelleFacette();
+        $table[$rubric_code][$nb]["nombre"]= $this->_nb_facettes_par_cle[$cle];
       }
     }
 
diff --git a/library/Class/MoteurRecherche/Result.php b/library/Class/MoteurRecherche/Result.php
new file mode 100644
index 00000000000..e6ca503cc54
--- /dev/null
+++ b/library/Class/MoteurRecherche/Result.php
@@ -0,0 +1,136 @@
+<?php
+/**
+ * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
+ *
+ * BOKEH is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
+ * the Free Software Foundation.
+ *
+ * There are special exceptions to the terms and conditions of the AGPL as it
+ * is applied to this software (see README file).
+ *
+ * BOKEH is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * along with BOKEH; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
+ */
+class Class_MoteurRecherche_Result {
+  const
+    ERROR = 'erreur';
+
+  protected
+    $_seach_engine,
+    $_records,
+    $_word_count = 0,
+    $_records_count = 0,
+    $_status = '',
+    $_breadcrumb,
+    $_rubrics = [],
+    $_error_message = '',
+    $_records_query = '',
+    $_facets_query = '',
+    $_criteres_recherche;
+
+  public function __construct($search_engine, $criteres_recherche) {
+    $this->_criteres_recherche = $criteres_recherche;
+    $this->_search_engine = $search_engine;
+  }
+
+
+  public function fetchFacetsAndTags($preferences) {
+    return $this->_search_engine->getFacettes($this->_facets_query,
+                                              $preferences);
+  }
+
+
+  public function fetchAllRecordsIds() {
+    return $this->_records_query
+      ? Class_Notice::getNoticeIdsByRequeteRecherche($this->_records_query)
+      : [];
+  }
+
+
+  public function fetchRecords() {
+    if ($this->_records_query && !isset($this->_records))
+      $this->_records = Class_Notice::findAllByRequeteRecherche($this->_records_query,
+                                                                $this->_criteres_recherche->getPageSize(),
+                                                                $this->_criteres_recherche->getPage());
+    return $this->_records;
+  }
+
+
+  public function recordsDo($closure) {
+    $this->fetchRecords();
+    array_map($closure, $this->_records);
+    return $this;
+  }
+
+
+  public function beError($message = '') {
+    $this->_status = static::ERROR;
+    $this->_error_message = $message;
+    return $this;
+  }
+
+
+  public function isError() {
+    return $this->_status === static::ERROR;
+  }
+
+
+  public function setBreadcrumb($breadcrumb) {
+    $this->_breadcrumb = $breadcrumb;
+    return $this;
+  }
+
+
+  public function getBreadcrumb() {
+    return $this->_breadcrumb;
+  }
+
+
+  public function setRubrics($rubrics) {
+    $this->_rubrics = $rubrics;
+    return $this;
+  }
+
+
+  public function getRubrics() {
+    return $this->_rubrics;
+  }
+
+
+  public function setRecordsQuery($query) {
+    $this->_records_query = $query;
+    return $this;
+  }
+
+
+  public function setRecordsCount($count) {
+    $this->_records_count = $count;
+    return $this;
+  }
+
+
+  public function getRecordsCount() {
+    return $this->_records_count;
+  }
+
+
+  public function setFacetsQuery($query) {
+    $this->_facets_query = $query;
+    return $this;
+  }
+
+
+  public function setWordCount($count) {
+    $this->_word_count = $count;
+    return $this;
+  }
+}
+
+?>
\ No newline at end of file
diff --git a/library/Class/MoteurRecherche/Resultat.php b/library/Class/MoteurRecherche/Resultat.php
deleted file mode 100644
index 349d6df6182..00000000000
--- a/library/Class/MoteurRecherche/Resultat.php
+++ /dev/null
@@ -1,35 +0,0 @@
-<?php
-/**
- * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
- *
- * BOKEH is free software; you can redistribute it and/or modify
- * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
- * the Free Software Foundation.
- *
- * There are special exceptions to the terms and conditions of the AGPL as it
- * is applied to this software (see README file).
- *
- * BOKEH is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
- *
- * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
- * along with BOKEH; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA 
- */
-class Class_MoteurRecherche_Resultat {
-  protected $_notices;
-
-  public function __construct($notices) {
-    $this->_notices = $notices;
-  }
-
-
-  public function acceptVisitor($visitor) {
-    foreach($this->_notices as $notice) 
-      $visitor->visitNotice($notice);
-  }
-}
-
-?>
\ No newline at end of file
diff --git a/library/Class/Notice/NavigationRecherche.php b/library/Class/Notice/NavigationRecherche.php
index b61382c037d..6ed66df4da0 100644
--- a/library/Class/Notice/NavigationRecherche.php
+++ b/library/Class/Notice/NavigationRecherche.php
@@ -68,13 +68,14 @@ class Class_Notice_NavigationRecherche {
 
 
   public function getAllNoticeIds() {
-    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']);
+    if (!isset($this->_all_notice_ids)) {
+        $this->_all_notice_ids = $this
+          ->_moteur_recherche
+          ->lancerRecherche($this->_criteres_recherche)
+          ->fetchAllRecordsIds();
     }
-    return isset($this->_all_notice_ids) ? $this->_all_notice_ids : [];
+
+    return $this->_all_notice_ids;
   }
 
 
diff --git a/library/ZendAfi/View/Helper/ListeNotices/ChronoSource.php b/library/ZendAfi/View/Helper/ListeNotices/ChronoSource.php
index 0f40c411ba8..96a95c075d8 100644
--- a/library/ZendAfi/View/Helper/ListeNotices/ChronoSource.php
+++ b/library/ZendAfi/View/Helper/ListeNotices/ChronoSource.php
@@ -27,9 +27,6 @@ class ZendAfi_View_Helper_ListeNotices_ChronoSource extends Zend_View_Helper_Htm
     $_current_date,
     $_preferences;
 
-  /**
-   * @param $resultat Class_MoteurRecherche_Resultat
-   */
   public function listeNotices_ChronoSource($notices, $preferences = []) {
     $this->_preferences = $preferences;
     $this->_dates = [];
diff --git a/tests/application/modules/opac/controllers/RechercheControllerTest.php b/tests/application/modules/opac/controllers/RechercheControllerTest.php
index e45cc807d2c..cab555aaad9 100644
--- a/tests/application/modules/opac/controllers/RechercheControllerTest.php
+++ b/tests/application/modules/opac/controllers/RechercheControllerTest.php
@@ -1067,19 +1067,18 @@ class RechercheControllerSimpleActionWithWrongParametersTest extends RechercheCo
 
 
 
-class RechercheControllerSimpleActionWithEmptyExpressionTest extends RechercheControllerSimpleActionTestCase {
+class RechercheControllerSimpleActionWithNoResultsTest extends RechercheControllerSimpleActionTestCase {
   public function setUp() {
     parent::setUp();
 
-    $this->dispatch('/recherche/simple/expressionRecherche/%', true);
+    $this->dispatch('/recherche/simple/expressionRecherche/%nuaisteauei', true);
   }
 
 
   /** @test */
-  public function pageShouldDisplayAucunMotSignificatif() {
+  public function pageShouldDisplayAucunResultatTrouve() {
     $this->assertXPathContentContains('//div//div//h2',
-                                      'Aucun résultat trouvé',
-                                      $this->_response->getBody());
+                                      'Aucun résultat trouvé');
   }
 }
 
@@ -1137,7 +1136,8 @@ class RechercheControllerSimpleActionWithListeFormatMurTest extends RechercheCon
 
   /** @test */
   public function urlForSousFacettesShouldContainsFacettesT1AndB1() {
-    $this->assertXPath('//div[@class="facette"]//a[contains(@href,"/facettes/T1-B1")]');
+    $this->assertXPath('//div[@class="facette"]//a[contains(@href,"/facettes/T1-B1")]',
+                       $this->_response->getBody());
   }
 
 
@@ -1149,7 +1149,7 @@ class RechercheControllerSimpleActionWithListeFormatMurTest extends RechercheCon
 
   /** @test */
   public function criteresRechercheShouldContainsBibAnnecy() {
-    $this->assertXPathContentContains('//div[@class="criteres_recherche"]//div[2]', 'Bibliothèque: Annecy', $this->_response->getBody());
+    $this->assertXPathContentContains('//div[@class="criteres_recherche"]//div[2]', 'Bibliothèque: Annecy');
   }
 
 
@@ -1683,11 +1683,12 @@ abstract class RechercheControllerSearchResultGuideeFixtures extends AbstractCon
     $this->mock_moteur_recherche
       ->whenCalled('lancerRecherche')
 
-      ->answers(["req_liste" => "select" ,
-                 "nombre" => 10,
-                 "req_facettes" => "select",
-                 'facettes' => 'M123-A989'
-                 ]);
+      ->answers((new Class_MoteurRecherche_Result($this->mock_moteur_recherche,
+                                                  new Class_CriteresRecherche()))
+                ->setRecordsQuery('select')
+                ->setRecordsCount(10)
+                ->setFacetsQuery('select'));
+
     Class_Codification::setInstance($this->mock_codif);
     Class_MoteurRecherche::setInstance($this->mock_moteur_recherche);
     $this->mock_sql
@@ -1792,15 +1793,17 @@ class RechercheControllerSimpleActionWithCatalogueAndDomainBrowserWidgetTest ext
   public function setUp() {
     parent::setUp();
     Class_CodifThesaurus::beVolatile();
-    Class_MoteurRecherche::setInstance(Storm_Test_ObjectWrapper::mock()
-                                       ->whenCalled('lancerRecherche')
-                                       ->answers(['req_liste' => '',
-                                                  'nombre' => 0,
-                                                  'req_facettes' => '',
-                                                  'statut' => 'erreur'])
-                                       ->whenCalled('getFacettes')
-                                       ->answers(['facettes' => ''])
-    );
+
+    $mock_moteur_recherche = Storm_Test_ObjectWrapper::mock();
+    $mock_moteur_recherche
+      ->whenCalled('lancerRecherche')
+      ->answers(new Class_MoteurRecherche_Result($mock_moteur_recherche,
+                                                 new Class_CriteresRecherche()))
+      ->whenCalled('getFacettes')
+      ->answers(['facettes' => [],
+                 'tags' => []]);
+
+    Class_MoteurRecherche::setInstance($mock_moteur_recherche);
 
     Class_Profil::getCurrentProfil()
       ->updateModuleConfigAccueil(9,
@@ -1870,15 +1873,16 @@ class RechercheControllerSimpleActionWithCatalogueAndNoParentsTest extends Reche
   public function setUp() {
     parent::setUp();
     Class_CodifThesaurus::beVolatile();
-    Class_MoteurRecherche::setInstance(Storm_Test_ObjectWrapper::mock()
-                                       ->whenCalled('lancerRecherche')
-                                       ->answers(['req_liste' => '',
-                                                  'nombre' => 0,
-                                                  'req_facettes' => '',
-                                                  'statut' => 'erreur'])
-                                       ->whenCalled('getFacettes')
-                                       ->answers(['facettes' => ''])
-    );
+
+    $mock_moteur_recherche = Storm_Test_ObjectWrapper::mock();
+    $mock_moteur_recherche
+      ->whenCalled('lancerRecherche')
+      ->answers(new Class_MoteurRecherche_Result($mock_moteur_recherche,
+                                                 new Class_CriteresRecherche()))
+      ->whenCalled('getFacettes')
+      ->answers(['facettes' => []]);
+
+
 
     $this->fixture('Class_Catalogue',
                    ['id'=>4,
@@ -1918,7 +1922,7 @@ class RechercheControllerActionSimpleWithResetTest extends AbstractControllerTes
 
 
 
-class RechercheControllerGuideeThesaurusTest extends  RechercheControllerGuideeHomePageTest{
+class RechercheControllerGuideeThesaurusTest extends  RechercheControllerGuideeHomePageTest {
   public function setUp() {
     parent::setUp();
 
-- 
GitLab