diff --git a/library/Class/MoteurRecherche.php b/library/Class/MoteurRecherche.php index 7e70e9af570c533bb6d58a1b14f385569219670b..5235dd778dcfeeefe33b9d7980ec4e21053c2107 100644 --- a/library/Class/MoteurRecherche.php +++ b/library/Class/MoteurRecherche.php @@ -364,7 +364,7 @@ class Class_MoteurRecherche { $this->conditions = ''; $this->_with_operator_conditions = []; $this->all_facettes = ''; - $this->select_notices = 'id_notice from notices'; + $this->select_notices = 'id_notice, facettes from notices'; $this->nb_mots = 0; $tri = $criteres_recherche->getTri(); $this->order_by = ($tri > '' && $tri !== '*') ? ' order by ' . $tri : ''; @@ -439,7 +439,11 @@ class Class_MoteurRecherche { $this->limite_facettes; // Lancer les requetes - $nb = fetchOne($req_comptage); + $search_result + ->setRecordsQuery($req_notices) + ->setFacetsQuery($req_facettes); + + $nb = $search_result->getRecordsCount(); if (!$nb && !$this->_shouldExtend()) { $this->addStatEchec(2, $criteres_recherche->getCriteres()); @@ -456,9 +460,6 @@ class Class_MoteurRecherche { } return $search_result - ->setRecordsQuery($req_notices) - ->setRecordsCount($nb) - ->setFacetsQuery($req_facettes) ->setWordCount($this->nb_mots); } diff --git a/library/Class/MoteurRecherche/Facettes.php b/library/Class/MoteurRecherche/Facettes.php index 8f6014ab1bc84a582d00a75713e903f75ffa8487..888f5962e5d9c7a7e7ee400f06328c36fc3661d8 100644 --- a/library/Class/MoteurRecherche/Facettes.php +++ b/library/Class/MoteurRecherche/Facettes.php @@ -34,6 +34,12 @@ class Class_MoteurRecherche_Facettes { } protected function _getFacettes($req,$preferences) { + return extractFacetsAndTags( + $this->fetchFacetsRows(Zend_Registry::get('sql')->fetchAllByColumn($req)), + $preferences); + } + + public function extractFacetsAndTags($codes_count, $preferences) { $result = ['facettes' => [], 'tags' => []]; @@ -47,10 +53,8 @@ class Class_MoteurRecherche_Facettes { "nombre" => $preferences["tags_nombre"]); if(!$p_facette["actif"] and !$p_tag["actif"]) - return $result; + return $result; - // Lecture des notices - $codes_count = $this->fetchFacetsRows($req); $result['facettes'] = $facettes = $this->groupAndOrderFacets($codes_count, $p_facette['types'], $p_facette['nombre']); @@ -58,21 +62,19 @@ class Class_MoteurRecherche_Facettes { if(!$p_tag["actif"]) return $result; - // Constituer le tableau des tags - $result['tags'] = $this->extractTags($p_tag['types'], $p_tag['nombre'], $codes_count); return $result; } - public function fetchFacetsRows($req) { + public function fetchFacetsRows($codes) { $all = array_count_values( array_filter( explode(' ', implode(' ', - Zend_Registry::get('sql')->fetchAllByColumn($req))))); + $codes)))); arsort($all); - return $all; + return array_slice($all, 0, 15000); } diff --git a/library/Class/MoteurRecherche/Result.php b/library/Class/MoteurRecherche/Result.php index 61fe59ae2872256aeca52a955e263e5520f123ac..a2a4b78b005fb8947a3179f0e6ca265cf39b562f 100644 --- a/library/Class/MoteurRecherche/Result.php +++ b/library/Class/MoteurRecherche/Result.php @@ -26,7 +26,7 @@ class Class_MoteurRecherche_Result { $_seach_engine, $_records, $_word_count = 0, - $_records_count = 0, + $_ids, $_status = '', $_breadcrumb, $_rubrics = [], @@ -57,23 +57,34 @@ class Class_MoteurRecherche_Result { public function fetchFacetsAndTags($preferences) { - return $this->_search_engine->getFacettes($this->_facets_query, - $preferences); + $search_facets = new Class_MoteurRecherche_Facettes(); + return isset($this->_facets) + ? $search_facets->extractFacetsAndTags($search_facets->fetchFacetsRows($this->_facets), + $preferences) + : $search_facets->getFacettes($this->_facets_query, + $preferences); } public function fetchAllRecordsIds() { - return $this->_records_query - ? Class_Notice::getNoticeIdsByRequeteRecherche($this->_records_query) - : []; + if (isset($this->_ids)) + return $this->_ids; + + if (!$this->_records_query) + return []; + + $data = Zend_Registry::get('sql')->fetchAll($this->_records_query, true, false); + $this->_ids = array_column($data, 0); + $this->_facets = array_column($data, 1); + return $this->_ids; } 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()); + $this->_records = Class_Notice::findAllByIds($this->fetchAllRecordsIds(), + $this->_criteres_recherche->getPageSize(), + $this->_criteres_recherche->getPage()); return $this->_records; } @@ -135,14 +146,8 @@ class Class_MoteurRecherche_Result { } - public function setRecordsCount($count) { - $this->_records_count = $count; - return $this; - } - - public function getRecordsCount() { - return $this->_records_count; + return count($this->fetchAllRecordsIds()); } diff --git a/library/Class/Notice.php b/library/Class/Notice.php index 117ff12aa19fc51aff5205927c380e3c10cf8492..a23a163306157f95a1fd8d7539d1053d00e9ed54 100644 --- a/library/Class/Notice.php +++ b/library/Class/Notice.php @@ -55,10 +55,12 @@ class NoticeLoader extends Storm_Model_Loader { public function findAllByRequeteRecherche($req, $nb_par_page, $page_no=1 ) { - if (!$page_no) $page_no=1; - - $ids = $this->getNoticeIdsByRequeteRecherche($req); + return $this->findAllByIds($this->getNoticeIdsByRequeteRecherche($req), + $nb_par_page, + $page_no); + } + public function findAllByIds($ids, $nb_par_page, $page_no) { if ($nb_par_page) $ids = array_slice($ids, ($page_no-1) * $nb_par_page,