Changeset 82579 in spip-zone
- Timestamp:
- May 19, 2014, 3:32:02 PM (7 years ago)
- Location:
- _plugins_/indexer/trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
_plugins_/indexer/trunk/iterateur/sphinx.php
r82569 r82579 53 53 * @var array 54 54 */ 55 protected $command = [];55 protected $command = array(); 56 56 57 57 /** … … 59 59 * @var array 60 60 */ 61 protected $info = [];61 protected $info = array(); 62 62 63 63 /** … … 77 77 * @var array 78 78 */ 79 protected $result = [];79 protected $result = array(); 80 80 81 81 /** … … 97 97 * @param array $info 98 98 */ 99 public function __construct($command, $info= []) {100 101 $this->command = $command + [102 'index' => [],103 'selection' => [],104 'recherche' => [],105 'snippet' => [],106 'facet' => [],107 ];99 public function __construct($command, $info=array()) { 100 101 $this->command = $command + array( 102 'index' => array(), 103 'selection' => array(), 104 'recherche' => array(), 105 'snippet' => array(), 106 'facet' => array(), 107 ); 108 108 109 109 #var_dump($this->command); … … 153 153 **/ 154 154 public function setIndex($index) { 155 if (!is_array($index)) $index = [$index];155 if (!is_array($index)) $index = array($index); 156 156 $index = array_filter($index); 157 157 if (!$index) { … … 175 175 **/ 176 176 public function setSelection($select) { 177 if (!is_array($select)) $select = [$select];177 if (!is_array($select)) $select = array($select); 178 178 $select = array_filter($select); 179 179 // si aucune selection demandée, on prend tout ! … … 196 196 **/ 197 197 public function setRecherche($recherche) { 198 if (!is_array($recherche)) $recherche = [$recherche];198 if (!is_array($recherche)) $recherche = array($recherche); 199 199 $recherche = array_filter($recherche); 200 200 if (!$recherche) { … … 210 210 211 211 public function setOrderby($orderby) { 212 if (!is_array($orderby)) $orderby = [$orderby];212 if (!is_array($orderby)) $orderby = array($orderby); 213 213 $orderby = array_filter($orderby); 214 214 if (!$orderby) { … … 253 253 public function setOneSnippet($desc) { 254 254 255 $desc += [255 $desc += array( 256 256 'champ' => 'content', 257 257 'phrase' => '', 258 258 'limit' => 200, 259 259 'as' => 'snippet' 260 ];260 ); 261 261 if (!$desc['phrase']) { 262 262 return false; … … 279 279 $phrase = $this->getSnippetAutoPhrase($command); 280 280 if (!$phrase) return false; 281 return $this->setOneSnippet( ['phrase' => $phrase]);281 return $this->setOneSnippet(array('phrase' => $phrase)); 282 282 } 283 283 … … 295 295 // mots de la recherche 296 296 $recherche = $command['recherche']; 297 if (!is_array($recherche)) $recherche = [$recherche];297 if (!is_array($recherche)) $recherche = array($recherche); 298 298 $recherche = array_filter($recherche); 299 299 $phrase .= implode(' ', $recherche); … … 350 350 continue; 351 351 } 352 $this->facet[] = ['alias' => $alias, 'query' => $query];352 $this->facet[] = array('alias' => $alias, 'query' => $query); 353 353 $this->sphinxQLQuery->facet($query); 354 354 } -
_plugins_/indexer/trunk/lib/Sphinx/SphinxQL/Query.php
r82568 r82579 7 7 */ 8 8 class Query{ 9 private $select = [];10 private $from = [];11 private $where = [];12 private $groupby = [];13 private $orderby = [];9 private $select = array(); 10 private $from = array(); 11 private $where = array(); 12 private $groupby = array(); 13 private $orderby = array(); 14 14 private $limit = ''; 15 private $facet = [];15 private $facet = array(); 16 16 17 17 public function __construct() {} … … 63 63 64 64 public function get() { 65 $query = [];65 $query = array(); 66 66 $this->removeEmpty(); 67 67 if ($this->select) $query[] = 'SELECT ' . implode(', ', $this->select); … … 76 76 77 77 private function removeEmpty() { 78 foreach ( ['select', 'from', 'where', 'groupby', 'orderby', 'facet']as $key) {78 foreach (array('select', 'from', 'where', 'groupby', 'orderby', 'facet') as $key) { 79 79 $this->$key = array_filter($this->$key); 80 80 #$this->$key = array_filter($this->key, 'strlen'); // leaves 0 -
_plugins_/indexer/trunk/lib/Sphinx/SphinxQL/SphinxQL.php
r82568 r82579 59 59 } 60 60 61 $liste = [62 'docs' => [],63 'facets' => [],64 'meta' => [],61 $liste = array( 62 'docs' => array(), 63 'facets' => array(), 64 'meta' => array(), 65 65 'query' => $query 66 ];66 ); 67 67 68 68 if ($docs = $this->query($query)) { … … 70 70 // 1) les documents trouvés 71 71 // 2+) les FACET à la suite 72 $reponses = [];72 $reponses = array(); 73 73 do { 74 74 $reponses[] = $docs->fetchAll(\PDO::FETCH_ASSOC); 75 75 } while ($docs->nextRowset()); 76 76 77 $meta = $this->query('SHOW meta');78 79 77 $liste['docs'] = array_shift($reponses); 80 78 $liste['facets'] = $this->parseFacets($reponses); 79 80 $meta = $this->query('SHOW meta'); 81 if ($errs = $this->sql->errorInfo()) { 82 # TODO: comprendre le pourquoi de l'erreur 83 # Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll(). Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute. 84 var_dump($errs); 85 } 81 86 if ($meta) { 82 87 $liste['meta'] = $this->parseMeta($meta->fetchAll(\PDO::FETCH_ASSOC)); … … 86 91 } 87 92 88 return ['query' => $liste];93 return array('query' => $liste); 89 94 } 90 95 … … 97 102 **/ 98 103 public function parseFacets($facettes) { 99 $facets = [];104 $facets = array(); 100 105 if (is_array($facettes)) { 101 106 foreach($facettes as $facette) { … … 111 116 } 112 117 if ($i == 0) { 113 $facets[$key] = [];118 $facets[$key] = array(); 114 119 } 115 120 $facets[$key][$value] = $nb; … … 126 131 */ 127 132 public function parseMeta($metas) { 128 $liste = [];133 $liste = array(); 129 134 foreach ($metas as $meta) { 130 135 $cle = $meta['Variable_name']; … … 136 141 137 142 if (!isset($liste[$cle])) { 138 $liste[$cle] = [];143 $liste[$cle] = array(); 139 144 } 140 145 … … 147 152 $liste['keywords'] = array(); 148 153 foreach ($liste['keyword'] as $index => $key) { 149 $liste['keywords'][$key] = [154 $liste['keywords'][$key] = array( 150 155 'keyword' => $key, 151 156 'docs' => $liste['docs'][$index], 152 157 'hits' => $liste['hits'][$index], 153 ];158 ); 154 159 } 155 160 unset($liste['keyword'], $liste['docs'], $liste['hits']);
Note: See TracChangeset
for help on using the changeset viewer.