Subversion Repositories Applications.referentiel

Compare Revisions

Ignore whitespace Rev 381 → Rev 382

/trunk/scripts/modules/algolia/algolia_apd.sql
1,4 → 1,4
SELECT b.num_nom AS apd_num_nom, b.num_nom_retenu AS apd_num_nom_retenu, b.num_tax_sup AS apd_num_tax_sup, b.rang AS apd_rang, b.nom_sci AS apd_nom_sci, b.auteur AS apd_auteur, b.annee AS apd_annee, apd_synonymes, b.`nom_supra_generique` AS apd_nom_supra_generique, b.`genre` AS apd_genre, b.`epithete_sp` AS apd_epithete_sp, b.`type_epithete` AS apd_type_epithete, b.`epithete_infra_sp` AS apd_epithete_infra_sp, b.`cultivar` AS apd_cultivar, b.`cultivar_groupe` AS apd_cultivar_groupe, concat('https://beta.tela-botanica.org/test/apd-nn-', b.`num_nom_retenu`) as apd_url,
SELECT b.num_nom AS apd_num_nom, b.num_nom_retenu AS apd_num_nom_retenu, b.num_tax_sup AS apd_num_tax_sup, b.rang AS apd_rang, b.nom_sci AS apd_nom_sci, b.auteur AS apd_auteur, b.annee AS apd_annee, b.`biblio_origine` AS apd_biblio, apd_synonymes, b.`nom_supra_generique` AS apd_nom_supra_generique, b.`genre` AS apd_genre, b.`epithete_sp` AS apd_epithete_sp, b.`type_epithete` AS apd_type_epithete, b.`epithete_infra_sp` AS apd_epithete_infra_sp, b.`cultivar` AS apd_cultivar, b.`cultivar_groupe` AS apd_cultivar_groupe, concat('https://beta.tela-botanica.org/test/apd-nn-', b.`num_nom_retenu`) as apd_url,
CASE WHEN b.rang > 290 THEN
concat('["',substr(`genre`, 1, 3),substr(`epithete_sp`, 1, 3), '","', substr(`genre`, 1, 2),' ',substr(`epithete_sp`, 1, 1),' ', substr(`epithete_infra_sp`, 1, 1), '","', substr(`genre`, 1, 2),' ',substr(`epithete_sp`, 1, 2), ' ', substr(`epithete_infra_sp`, 1, 1),'","', substr(`genre`, 1, 2),' ',substr(`epithete_sp`, 1, 3),' ', substr(`epithete_infra_sp`, 1, 1), '","', substr(`genre`, 1, 3),' ',substr(`epithete_sp`, 1, 1),' ', substr(`epithete_infra_sp`, 1, 1),'","', substr(`genre`, 1, 3),' ',substr(`epithete_sp`, 1, 2),' ', substr(`epithete_infra_sp`, 1, 1), '","', substr(`genre`, 1, 3),' ',substr(`epithete_sp`, 1, 3),' ', substr(`epithete_infra_sp`, 1, 1), '","', substr(`genre`, 1, 4),' ',substr(`epithete_sp`, 1, 1),' ', substr(`epithete_infra_sp`, 1, 1), '","', substr(`genre`, 1, 4),' ',substr(`epithete_sp`, 1, 2),' ', substr(`epithete_infra_sp`, 1, 1), '","', substr(`genre`, 1, 4),' ',substr(`epithete_sp`, 1, 3),' ', substr(`epithete_infra_sp`, 1, 1),'","',
substr(`genre`, 1, 2),' ',substr(`epithete_sp`, 1, 1),' ', substr(`epithete_infra_sp`, 1, 2), '","', substr(`genre`, 1, 2),' ',substr(`epithete_sp`, 1, 2), ' ', substr(`epithete_infra_sp`, 1, 2),'","', substr(`genre`, 1, 2),' ',substr(`epithete_sp`, 1, 3),' ', substr(`epithete_infra_sp`, 1, 2), '","', substr(`genre`, 1, 3),' ',substr(`epithete_sp`, 1, 1),' ', substr(`epithete_infra_sp`, 1, 2),'","', substr(`genre`, 1, 3),' ',substr(`epithete_sp`, 1, 2),' ', substr(`epithete_infra_sp`, 1, 2), '","', substr(`genre`, 1, 3),' ',substr(`epithete_sp`, 1, 3),' ', substr(`epithete_infra_sp`, 1, 2), '","', substr(`genre`, 1, 4),' ',substr(`epithete_sp`, 1, 1),' ', substr(`epithete_infra_sp`, 1, 2), '","', substr(`genre`, 1, 4),' ',substr(`epithete_sp`, 1, 2),' ', substr(`epithete_infra_sp`, 1, 2), '","', substr(`genre`, 1, 4),' ',substr(`epithete_sp`, 1, 3),' ', substr(`epithete_infra_sp`, 1, 2),'","',
12,7 → 12,7
FROM `apd` b, (SELECT num_nom_retenu, concat('[',group_concat('"',nom_sci,' ',auteur,'"'),']') AS apd_synonymes FROM apd WHERE num_nom != num_nom_retenu AND num_nom_retenu != 0 GROUP BY `num_nom_retenu`) as c
WHERE (b.num_nom_retenu = c.num_nom_retenu) AND b.num_nom = b.num_nom_retenu
UNION
SELECT b.num_nom AS apd_num_nom, b.num_nom_retenu AS apd_num_nom_retenu, b.num_tax_sup AS apd_num_tax_sup, b.rang AS apd_rang, b.nom_sci AS apd_nom_sci, b.auteur AS apd_auteur, b.annee AS apd_annee, '' as apd_synonymes, b.`nom_supra_generique` AS apd_nom_supra_generique, b.`genre` AS apd_genre, b.`epithete_sp` AS apd_epithete_sp, b.`type_epithete` AS apd_type_epithete, b.`epithete_infra_sp` AS apd_epithete_infra_sp, b.`cultivar` AS apd_cultivar, b.`cultivar_groupe` AS apd_cultivar_groupe, concat('https://beta.tela-botanica.org/test/apd-nn-', b.`num_nom_retenu`) as apd_url,
SELECT b.num_nom AS apd_num_nom, b.num_nom_retenu AS apd_num_nom_retenu, b.num_tax_sup AS apd_num_tax_sup, b.rang AS apd_rang, b.nom_sci AS apd_nom_sci, b.auteur AS apd_auteur, b.annee AS apd_annee, b.`biblio_origine` AS apd_biblio, '' as apd_synonymes, b.`nom_supra_generique` AS apd_nom_supra_generique, b.`genre` AS apd_genre, b.`epithete_sp` AS apd_epithete_sp, b.`type_epithete` AS apd_type_epithete, b.`epithete_infra_sp` AS apd_epithete_infra_sp, b.`cultivar` AS apd_cultivar, b.`cultivar_groupe` AS apd_cultivar_groupe, concat('https://beta.tela-botanica.org/test/apd-nn-', b.`num_nom_retenu`) as apd_url,
CASE WHEN b.rang > 290 THEN
concat('["',substr(`genre`, 1, 3),substr(`epithete_sp`, 1, 3), '","', substr(`genre`, 1, 2),' ',substr(`epithete_sp`, 1, 1),' ', substr(`epithete_infra_sp`, 1, 1), '","', substr(`genre`, 1, 2),' ',substr(`epithete_sp`, 1, 2), ' ', substr(`epithete_infra_sp`, 1, 1),'","', substr(`genre`, 1, 2),' ',substr(`epithete_sp`, 1, 3),' ', substr(`epithete_infra_sp`, 1, 1), '","', substr(`genre`, 1, 3),' ',substr(`epithete_sp`, 1, 1),' ', substr(`epithete_infra_sp`, 1, 1),'","', substr(`genre`, 1, 3),' ',substr(`epithete_sp`, 1, 2),' ', substr(`epithete_infra_sp`, 1, 1), '","', substr(`genre`, 1, 3),' ',substr(`epithete_sp`, 1, 3),' ', substr(`epithete_infra_sp`, 1, 1), '","', substr(`genre`, 1, 4),' ',substr(`epithete_sp`, 1, 1),' ', substr(`epithete_infra_sp`, 1, 1), '","', substr(`genre`, 1, 4),' ',substr(`epithete_sp`, 1, 2),' ', substr(`epithete_infra_sp`, 1, 1), '","', substr(`genre`, 1, 4),' ',substr(`epithete_sp`, 1, 3),' ', substr(`epithete_infra_sp`, 1, 1),'","',
substr(`genre`, 1, 2),' ',substr(`epithete_sp`, 1, 1),' ', substr(`epithete_infra_sp`, 1, 2), '","', substr(`genre`, 1, 2),' ',substr(`epithete_sp`, 1, 2), ' ', substr(`epithete_infra_sp`, 1, 2),'","', substr(`genre`, 1, 2),' ',substr(`epithete_sp`, 1, 3),' ', substr(`epithete_infra_sp`, 1, 2), '","', substr(`genre`, 1, 3),' ',substr(`epithete_sp`, 1, 1),' ', substr(`epithete_infra_sp`, 1, 2),'","', substr(`genre`, 1, 3),' ',substr(`epithete_sp`, 1, 2),' ', substr(`epithete_infra_sp`, 1, 2), '","', substr(`genre`, 1, 3),' ',substr(`epithete_sp`, 1, 3),' ', substr(`epithete_infra_sp`, 1, 2), '","', substr(`genre`, 1, 4),' ',substr(`epithete_sp`, 1, 1),' ', substr(`epithete_infra_sp`, 1, 2), '","', substr(`genre`, 1, 4),' ',substr(`epithete_sp`, 1, 2),' ', substr(`epithete_infra_sp`, 1, 2), '","', substr(`genre`, 1, 4),' ',substr(`epithete_sp`, 1, 3),' ', substr(`epithete_infra_sp`, 1, 2),'","',
/trunk/scripts/modules/algolia/Algolia.php
49,6 → 49,19
$this->algolia = new \AlgoliaSearch\Client(Config::get('algolia_application_id'), Config::get('algolia_api_key'));
$this->indexAlgolia = $this->algolia->initIndex(Config::get('algolia_index'));
 
/*$settings = $this->indexAlgolia->getSettings();
var_dump(json_encode($settings));
exit;*/
 
// Réglages de l'index @TODO tenir à jour
if ($this->confirmer("Charger les réglages par défaut (index_settings.json) dans la configuration de l'index Algolia ?")) {
// Chargement des réglages par défaut
$reglagesJson = file_get_contents(dirname(__FILE__) . '/index_settings.json');
$reglages = json_decode($reglagesJson, true);
$this->indexAlgolia->setSettings($reglages);
echo "Réglages chargés dans Algolia" . PHP_EOL;
}
 
// Connexion à la base
$this->connecterPDO();
 
91,7 → 104,9
}
 
// Confirmation
//$this->confirmer("Fusion des référentiels [" . implode(',', $refs) . "] et mise à jour de [" . implode(',', $refsMaj) . "]. Continuer ?");
if (! $this->confirmer("Fusion des référentiels [" . implode(',', $refs) . "] et mise à jour de [" . implode(',', $refsMaj) . "]. Continuer ?")) {
exit;
}
 
//var_dump($refs);
$donneesBrutes = array();
119,7 → 134,7
 
// Mise en forme
$index = $this->mettreEnForme($index);
$this->extrait($index, 3);
//$this->extrait($index, 3);
 
// Stats
$taille = count($index);
215,7 → 230,7
$url = $taxon[$ref . '_url'];
$synonymes = json_decode($taxon[$ref . '_synonymes'], true);
$raccourcis = json_decode($taxon[$ref . '_shortcuts'], true);
$raccourcis = array_values(array_unique($raccourcis)); // array_values réindexe pour obtenir une liste en JSON et non un objet
$raccourcis = ($raccourcis != null ? array_values(array_unique($raccourcis)) : null); // array_values réindexe pour obtenir une liste en JSON et non un objet
// garniture
$donneesRef = array(
'nomenclatural_number' => intval($nn),
245,8 → 260,9
}
 
protected function insererDansAlgolia($index) {
echo "++++ Insertion dans Algolia !! ++++" . PHP_EOL;
$tranche = array_slice($index, 0, 500);
$tailleTranche = 30000;
echo "++++ Insertion dans Algolia ($tailleTranche) !! ++++" . PHP_EOL;
$tranche = array_slice($index, 0, $tailleTranche);
//var_dump($tranche);
//$trancheJSON = json_encode($tranche);
$this->indexAlgolia->addObjects($tranche);
309,9 → 325,10
$line = fgets($handle);
if(strtolower(trim($line)) != strtolower($codeAcceptation)) {
echo $messageAnnulation . PHP_EOL;
exit;
return false;
}
fclose($handle);
return true;
}
}
?>
/trunk/scripts/modules/algolia/index_settings.json
New file
0,0 → 1,86
{
"minWordSizefor1Typo": 4,
"minWordSizefor2Typos": 8,
"hitsPerPage": 50,
"maxValuesPerFacet": 100,
"version": 2,
"searchableAttributes": [
"unordered(shortcuts)",
"bdtfx.scientific_name",
"bdtfx.common_name",
"unordered(bdtfx.nomenclatural_number)",
"bdtfx.synonyms",
"unordered(bdtfx.supra_genus_name)",
"unordered(bdtfx.year)",
"apd.scientific_name",
"apd.common_name",
"unordered(apd.nomenclatural_number)",
"apd.synonyms",
"unordered(apd.supra_genus_name)",
"unordered(apd.year)",
"isfan.scientific_name",
"isfan.common_name",
"unordered(isfan.nomenclatural_number)",
"isfan.synonyms",
"unordered(isfan.supra_genus_name)",
"unordered(isfan.year)",
"bdtxa.scientific_name",
"bdtxa.common_name",
"unordered(bdtxa.nomenclatural_number)",
"bdtxa.synonyms",
"unordered(bdtxa.supra_genus_name)",
"unordered(bdtxa.year)"
],
"numericAttributesToIndex": [
"bdtfx.year",
"apd.year",
"isfan.year",
"bdtxa.year",
"bdtfx.rank",
"apd.rank",
"isfan.rank",
"bdtxa.rank"
],
"attributesToRetrieve": null,
"allowTyposOnNumericTokens": false,
"ignorePlurals": false,
"advancedSyntax": false,
"removeStopWords": false,
"replaceSynonymsInHighlight": true,
"distinct": false,
"unretrievableAttributes": null,
"optionalWords": null,
"attributesForFaceting": null,
"attributesToSnippet": null,
"attributesToHighlight": null,
"paginationLimitedTo": 1000,
"attributeForDistinct": null,
"exactOnSingleWordQuery": "attribute",
"ranking": [
"typo",
"geo",
"words",
"filters",
"proximity",
"attribute",
"exact",
"custom"
],
"customRanking": [
"desc(bdtfx.scientific_name)",
"desc(apd.scientific_name)",
"desc(isfan.scientific_name)",
"desc(bdtxa.scientific_name)"
],
"separatorsToIndex": "",
"removeWordsIfNoResults": "none",
"queryType": "prefixLast",
"highlightPreTag": "<em>",
"highlightPostTag": "</em>",
"snippetEllipsisText": "",
"typoTolerance": "true",
"alternativesAsExact": [
"ignorePlurals",
"singleWordSynonym"
]
}