Skip to content
Snippets Groups Projects
Commit 334c03f6 authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

rel #21441 : fix perf

parent a11cd84d
Branches
Tags
3 merge requests!1132Hotline#29412 images des articles dans le resultat de recherche,!1120Master,!1075Dev#21441 creer des facettes a partir des custom fields
......@@ -76,9 +76,10 @@ class Class_MoteurRecherche_Facettes {
$facettes = [];
$facettes_instances = [];
foreach($rows as $notice)
$facettes_instances = array_merge($facettes_instances,
Class_Notice_Facette::parseFacettesFromNoticeField($notice['facettes']));
foreach($rows as $record) {
foreach(Class_Notice_Facette::parseFacettesFromNoticeField($record['facettes']) as $facet)
$facettes_instances[] = $facet;
}
foreach($facettes_instances as $facet) {
$cle = $facet->getCle();
......
......@@ -19,73 +19,66 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class Class_Notice_Facette {
const NB_CHAR_THESAURUS=4;
protected static $_instances=[];
const NB_CHAR_THESAURUS = 4;
protected static $_instances = [];
protected
$_cle,
$_rubrique;
public static function parseFacettesFromNoticeField($str_facettes) {
$items = array_filter(explode(" ",trim($str_facettes)));
$facettes=[];
foreach($items as $item) {
$items = array_filter(explode(' ', trim($str_facettes)));
$facettes = [];
foreach($items as $item)
$facettes[] = static::find($item);
}
return $facettes;
}
public static function find($cle) {
if (isset(static::$_instances[$cle]))
return static::$_instances[$cle];
return static::$_instances[$cle] = new static($cle);
return (array_key_exists($cle, static::$_instances)) ?
static::$_instances[$cle]:
static::$_instances[$cle] = new static($cle);
}
public function __construct($cle) {
$this->_cle=$cle;
$this->_cle = $cle;
$this->_rubrique = Class_Notice_RubriqueFacette::find($this->getCodeRubriqueFromCle($cle));
}
/**
* @return String exemple : Y
*/
public function getCodeRubrique() {
return $this->_rubrique->getCode();
}
/**
* @return int example : 8
*/
public function getValue() {
return substr($this->_cle, 1);
}
public function getCodeRubriqueFromCle($cle) {
if ($cle[0] !== 'H')
return $cle[0];
return substr($cle,0,self::NB_CHAR_THESAURUS+1);
$code = substr($cle, 0, 1);
return Class_CodifThesaurus::CODE_FACETTE != $code ?
$code : substr($cle, 0, self::NB_CHAR_THESAURUS + 1);
}
public function getCodeRubriqueLibelle() {
return $this->_rubrique->getLibelle();
}
/**
* @return String exemple : Y88
*/
public function getCle() {
return $this->_cle;
}
/**
* @return String exemple : Comédie dramatique
*/
public function getLibelleFacette() {
return Class_Codification::getInstance()->getLibelleFacette($this->_cle);
return Class_Codification::getInstance()->getLibelleFacette($this->_cle);
}
}
?>
\ No newline at end of file
}
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment