| Line 123... |
Line 123... |
| 123 |
foreach ($refs as $ref) {
|
123 |
foreach ($refs as $ref) {
|
| 124 |
$fichierRequete = dirname(__FILE__) . "/algolia_" . $ref . ".sql";
|
124 |
$fichierRequete = dirname(__FILE__) . "/algolia_" . $ref . ".sql";
|
| 125 |
// Exécution de la requête
|
125 |
// Exécution de la requête
|
| 126 |
$requete = file_get_contents($fichierRequete);
|
126 |
$requete = file_get_contents($fichierRequete);
|
| 127 |
$resultat = $this->requete($requete);
|
127 |
$resultat = $this->requete($requete);
|
| 128 |
/*while ($ligne = $resultat->fetch()) {
|
- |
|
| 129 |
var_dump($ligne);
|
- |
|
| 130 |
break;
|
- |
|
| 131 |
}*/
|
- |
|
| 132 |
$donneesBrutes[$ref] = $resultat->fetchAll();
|
128 |
$donneesBrutes[$ref] = $resultat->fetchAll();
|
| Line 133... |
Line 129... |
| 133 |
|
129 |
|
| 134 |
// Info utilisation mémoire
|
130 |
// Info utilisation mémoire
|
| 135 |
$mem = memory_get_usage(true);
|
131 |
$mem = memory_get_usage(true);
|
| Line 141... |
Line 137... |
| 141 |
$index = $this->fusionnerReferentiels($donneesBrutes);
|
137 |
$index = $this->fusionnerReferentiels($donneesBrutes);
|
| 142 |
//$this->extrait($index, array('Acacia dealbata Link','Acacia Mill.','Fabaceae'));
|
138 |
//$this->extrait($index, array('Acacia dealbata Link','Acacia Mill.','Fabaceae'));
|
| Line 143... |
Line 139... |
| 143 |
|
139 |
|
| 144 |
// Mise en forme
|
140 |
// Mise en forme
|
| 145 |
$index = $this->mettreEnForme($index);
|
141 |
$index = $this->mettreEnForme($index);
|
| Line 146... |
Line 142... |
| 146 |
//$this->extrait($index, 3);
|
142 |
//$this->extrait($index, 100);
|
| 147 |
|
143 |
|
| 148 |
// Stats
|
144 |
// Stats
|
| 149 |
$taille = count($index);
|
145 |
$taille = count($index);
|
| Line 150... |
Line 146... |
| 150 |
echo "Taille de l'index: [$taille] lignes !" . PHP_EOL;
|
146 |
echo "Taille de l'index: [$taille] lignes !" . PHP_EOL;
|
| - |
|
147 |
//file_put_contents("couscous.json", json_encode($index));
|
| - |
|
148 |
|
| 151 |
//file_put_contents("couscous.json", json_encode($index));
|
149 |
// Calcul des différences ?
|
| - |
|
150 |
// @TODO bonjour la galère
|
| - |
|
151 |
|
| - |
|
152 |
// Insertion ?
|
| 152 |
|
153 |
if (! $this->confirmer("Prêt à insérer dans l'index Algolia [" . Config::get('algolia_index') . "]. Continuer ?")) {
|
| Line 153... |
Line 154... |
| 153 |
// Calcul des différences ?
|
154 |
exit;
|
| 154 |
// Insertion ?
|
155 |
}
|
| 155 |
$this->insererDansAlgolia($index);
|
156 |
$this->insererDansAlgolia($index);
|
| Line 168... |
Line 169... |
| 168 |
foreach ($donneesRefs as $ref => &$d) {
|
169 |
foreach ($donneesRefs as $ref => &$d) {
|
| 169 |
$nbTaxons = count($d);
|
170 |
$nbTaxons = count($d);
|
| 170 |
echo "-- fusion du référentiel [$ref] : $nbTaxons taxons --" . PHP_EOL;
|
171 |
echo "-- fusion du référentiel [$ref] : $nbTaxons taxons --" . PHP_EOL;
|
| Line 171... |
Line 172... |
| 171 |
|
172 |
|
| - |
|
173 |
$fusions = 0;
|
| 172 |
$fusions = 0;
|
174 |
|
| - |
|
175 |
foreach ($d as $taxon) {
|
| - |
|
176 |
// debug
|
| - |
|
177 |
/*if ($taxon[$ref . '_num_nom'] == 141) {
|
| - |
|
178 |
echo "> Taxon 141 :" . PHP_EOL;
|
| - |
|
179 |
var_dump($taxon);
|
| - |
|
180 |
echo PHP_EOL;
|
| 173 |
foreach ($d as $taxon) {
|
181 |
}*/
|
| 174 |
$nomSci = $taxon[$ref . '_nom_sci'];
|
182 |
$nomSci = $taxon[$ref . '_nom_sci'];
|
| 175 |
//$nn = $taxon[$ref . '_num_nom'];
|
183 |
//$nn = $taxon[$ref . '_num_nom'];
|
| 176 |
// Ajout du nom d'auteur pour éviter les collisions dans un même référentiel
|
184 |
// Ajout du nom d'auteur pour éviter les collisions dans un même référentiel
|
| 177 |
if (! empty ($taxon[$ref . '_auteur'])) {
|
185 |
if (! empty ($taxon[$ref . '_auteur'])) {
|
| Line 236... |
Line 244... |
| 236 |
$cultivar = $taxon[$ref . '_cultivar'];
|
244 |
$cultivar = $taxon[$ref . '_cultivar'];
|
| 237 |
$cultivar_groupe = $taxon[$ref . '_cultivar_groupe'];
|
245 |
$cultivar_groupe = $taxon[$ref . '_cultivar_groupe'];
|
| 238 |
$nomCommun = (isset($taxon[$ref . '_nom_francais']) ? $taxon[$ref . '_nom_francais'] : '');
|
246 |
$nomCommun = (isset($taxon[$ref . '_nom_francais']) ? $taxon[$ref . '_nom_francais'] : '');
|
| 239 |
$url = $taxon[$ref . '_url'];
|
247 |
$url = $taxon[$ref . '_url'];
|
| 240 |
$synonymes = json_decode($taxon[$ref . '_synonymes'], true);
|
248 |
$synonymes = json_decode($taxon[$ref . '_synonymes'], true);
|
| - |
|
249 |
// debug synonymes tronqués (group_concat limité en longueur)
|
| - |
|
250 |
/*if ($nn == 141) {
|
| - |
|
251 |
echo ">> Synonymes bruts: [" . $taxon[$ref . '_synonymes'] . "]" . PHP_EOL;
|
| - |
|
252 |
echo ">> Synonymes décodés: [" . print_r($synonymes, true) . "]" . PHP_EOL;
|
| - |
|
253 |
exit;
|
| - |
|
254 |
}*/
|
| 241 |
$raccourcis = json_decode($taxon[$ref . '_shortcuts'], true);
|
255 |
$raccourcis = json_decode($taxon[$ref . '_shortcuts'], true);
|
| 242 |
$raccourcis = ($raccourcis != null ? array_values(array_unique($raccourcis)) : null); // array_values réindexe pour obtenir une liste en JSON et non un objet
|
256 |
$raccourcis = ($raccourcis != null ? array_values(array_unique($raccourcis)) : null); // array_values réindexe pour obtenir une liste en JSON et non un objet
|
| 243 |
// garniture
|
257 |
// garniture
|
| 244 |
$donneesRef = array(
|
258 |
$donneesRef = array(
|
| 245 |
'nomenclatural_number' => intval($nn),
|
259 |
'nomenclatural_number' => intval($nn),
|
| Line 258... |
Line 272... |
| 258 |
'attribute_type' => $type_epithete,
|
272 |
'attribute_type' => $type_epithete,
|
| 259 |
'infra_species_attribute' => $epithete_infra_sp,
|
273 |
'infra_species_attribute' => $epithete_infra_sp,
|
| 260 |
'cultivar' => $cultivar,
|
274 |
'cultivar' => $cultivar,
|
| 261 |
'cultivar_groupe' => $cultivar_groupe
|
275 |
'cultivar_groupe' => $cultivar_groupe
|
| 262 |
);
|
276 |
);
|
| - |
|
277 |
// dans le cas de BDTFX, ajout de l'illustration de Coste et de
|
| - |
|
278 |
// la carte Chorodep pour illustrer les résultats de recherche
|
| - |
|
279 |
if ($ref == "bdtfx" && (Config::get("activer_image_coste") == "1")) {
|
| - |
|
280 |
$this->ajouterImagesCosteEtChorodep($nn, $donneesRef);
|
| - |
|
281 |
}
|
| - |
|
282 |
|
| 263 |
$nouveauTaxon[$ref] = $donneesRef;
|
283 |
$nouveauTaxon[$ref] = $donneesRef;
|
| 264 |
$nouveauTaxon['shortcuts'] = $raccourcis;
|
284 |
$nouveauTaxon['shortcuts'] = $raccourcis;
|
| 265 |
}
|
285 |
}
|
| 266 |
$nouvelIndex[] = $nouveauTaxon;
|
286 |
$nouvelIndex[] = $nouveauTaxon;
|
| 267 |
}
|
287 |
}
|
| 268 |
return $nouvelIndex;
|
288 |
return $nouvelIndex;
|
| 269 |
}
|
289 |
}
|
| Line 270... |
Line 290... |
| 270 |
|
290 |
|
| - |
|
291 |
/**
|
| - |
|
292 |
* Interroge le service eFlore pour récupérer l'illustration de Coste pour
|
| - |
|
293 |
* le nn en cours, et ajoute une URL pour obtenir la carte de répartition
|
| - |
|
294 |
* de Chorodep
|
| - |
|
295 |
*/
|
| - |
|
296 |
protected function ajouterImagesCosteEtChorodep($nn, &$donnees) {
|
| - |
|
297 |
// carte de répartition - le service renvoie directement une image
|
| - |
|
298 |
$donnees['thumbnails.chorodep'] = sprintf(Config::get('url_template_chorodep'), $nn);
|
| - |
|
299 |
// Coste
|
| - |
|
300 |
$urlServiceCoste = sprintf(Config::get('url_template_coste'), $nn);
|
| - |
|
301 |
$retour = @file_get_contents($urlServiceCoste);
|
| - |
|
302 |
if ($retour) {
|
| - |
|
303 |
try {
|
| - |
|
304 |
$infosCoste = json_decode($retour, true);
|
| - |
|
305 |
if (! empty($infosCoste['resultats']) && is_array($infosCoste['resultats'])) {
|
| - |
|
306 |
$res1 = array_shift($infosCoste['resultats']);
|
| - |
|
307 |
if (is_array($res1) && ! empty($res1['binaire.href'])) {
|
| - |
|
308 |
$donnees['thumbnails.coste'] = $res1['binaire.href'];
|
| - |
|
309 |
}
|
| - |
|
310 |
}
|
| - |
|
311 |
} catch (Exception $ex) {
|
| - |
|
312 |
// pas de bol
|
| - |
|
313 |
}
|
| - |
|
314 |
}
|
| - |
|
315 |
// debug
|
| - |
|
316 |
/*echo ">> nn : [$nn]" . PHP_EOL;
|
| - |
|
317 |
echo ">> image Coste : [" . $donnees['thumbnails.coste'] . "]" . PHP_EOL;
|
| - |
|
318 |
echo ">> carte Chorodep : [" . $donnees['thumbnails.chorodep'] . "]" . PHP_EOL;*/
|
| - |
|
319 |
}
|
| - |
|
320 |
|
| 271 |
/**
|
321 |
/**
|
| 272 |
* Appelle l'API Algolia pour indexer les données présentes dans $index, par
|
322 |
* Appelle l'API Algolia pour indexer les données présentes dans $index, par
|
| 273 |
* tranches.
|
323 |
* tranches.
|
| 274 |
*/
|
324 |
*/
|
| 275 |
protected function insererDansAlgolia(&$index) {
|
325 |
protected function insererDansAlgolia(&$index) {
|