Changeset 93505 in spip-zone
- Timestamp:
- Dec 10, 2015, 9:19:11 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
_plugins_/indexer/trunk/spip-cli/SphinxGenererAutocomplete.php
r93485 r93505 40 40 // On se fait un dossier temporaire pour enregistrer le dictionnaire complet 41 41 $dossier_tmp = sous_repertoire(_DIR_TMP . 'sphinx/'); 42 $dict_tmp = $dossier_tmp . $index . '.dict.txt'; 43 44 // On se fait un dossier final 45 $dossier_autocomplete = sous_repertoire(_DIR_IMG . 'indexer_autocomplete'); 42 46 43 47 $sphinxql = new \Sphinx\SphinxQL\SphinxQL(SPHINX_SERVER_HOST, SPHINX_SERVER_PORT); … … 49 53 if ($spis = glob($dossier_data . $index . '.*.spi') and $spi = $spis[0]) { 50 54 if (function_exists('passthru')) { 51 passthru("indextool --dumpdict $spi > {$dossier_tmp}{$index}.dict.txt"); 55 passthru("indextool --dumpdict {$spi} > {$dict_tmp}"); 56 57 // Si on a bien le dictionnaire voulu à la fin 58 if (file_exists($dict_tmp)) { 59 $output->writeln("<info>Dictionnaire correctement créé dans {$dict_tmp}</info>"); 60 61 $this->analyser_dictionnaire( 62 $dossier_autocomplete, 63 $dict_tmp, 64 find_in_path('autocomplete/exceptions.txt') 65 ); 66 } 52 67 } 53 68 else { … … 59 74 } 60 75 } 76 77 protected function analyser_dictionnaire($rep, $dict, $exceptions) { 78 include_spip('inc/charsets'); 79 $ab = ''; 80 81 $exceptions = array_map('trim', file($exceptions)); 82 83 foreach(file($dict) as $k => $l) { 84 list($keyword,$docs,$hits,$offset) = explode(',', $l); 85 86 // Quand le tableau mots-fréquences commence, on démarre 87 if ($keyword === 'keyword' and $docs === 'docs') { 88 $start = true; 89 } 90 91 if ($start AND ord($l) != 2) { 92 if (!in_array($keyword, $exceptions)) { 93 $_ab = strtolower(translitteration(mb_substr($keyword, 0, 2))); 94 if ($_ab !== $ab) { 95 $this->save($ab, $mots, $rep); 96 $ab = $_ab; 97 $mots = []; 98 } 99 // conserver les mots ayant un nombre suffisant d'occurrences 100 if ($hits >= 3) { 101 $mots[$keyword] = $hits; 102 } 103 } 104 } 105 } 106 107 $this->save($ab, $mots, $rep); 108 } 109 110 // enregistrer la liste ab - triée par hits décroissants 111 protected function save($ab, $mots, $rep) { 112 if (empty($mots)) return; 113 if (!preg_match(',[a-z][a-z],S', $ab)) return; 114 115 arsort($mots); 116 $dump = join("\n", array_keys($mots)); 117 $a = mb_substr($ab, 0,1); 118 if (!is_dir($rep.'/'.$a)) mkdir ($rep.'/'.$a); 119 $res = ($fp = fopen($rep.'/'.$a.'/'.$ab.'.txt', 'w')) 120 && fwrite ($fp, $dump) 121 && fclose ($fp); 122 spip_log("autocomplete dict $ab " . count($mots) . " ($res)"); 123 return $res; 124 } 61 125 }
Note: See TracChangeset
for help on using the changeset viewer.