Changeset 1185 for solr/files/lib/data/solr/SolrBridge.php
- Timestamp:
- 06/26/10 13:29:33 (3 years ago)
- Files:
-
- 1 modified
-
solr/files/lib/data/solr/SolrBridge.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
solr/files/lib/data/solr/SolrBridge.php
r1184 r1185 1 1 <?php 2 // wcf imports 3 require_once(WCF_DIR.'lib/data/message/search/SearchEngine.class.php'); 4 require_once(WCF_DIR.'lib/data/solr/SolrService.php'); 5 2 6 3 7 /** … … 24 28 25 29 // load search type objects 26 SearchEngne::getSearchTypes(); 27 28 $path = parse_url(SOLR_URL); 29 $this->solr = new SolrService($path['host'], isset($path['port']) ? $path['port'] : 80, $path['path']); 30 SearchEngine::getSearchTypes(); 31 32 $this->solr = new SolrService(); 30 33 } 31 34 … … 40 43 $sql = "INSERT IGNORE INTO 41 44 wcf".WCF_N."_solr_index 42 (type Name, messageID)";45 (typeID, messageID)"; 43 46 foreach($this->documents as $doc) { 44 47 $sql .= ""; //TODO: mark as done … … 55 58 * 56 59 */ 57 protected function getTotals(array $types ) {60 protected function getTotals(array $types, $func) { 58 61 59 62 $sql = ''; … … 70 73 71 74 $sql .= "( 72 SELECT MAX(".$messageIDFieldName.") AS messageID,75 SELECT ".$func."(".$messageIDFieldName.") AS messageID, 73 76 '".$type."' AS messageType 74 77 FROM ".$doc->getTableName()." messageTable 75 78 ".$doc->getJoins()." 76 WHERE 177 ".(!empty($conditions[$type]) ? " ".(!empty($q) ? "AND" : "")." (".$conditions[$type].")" : "")."78 GROUP BY messageID79 79 )"; 80 80 } … … 82 82 // send search query 83 83 $types = array(); 84 $result = WCF::getDB()->sendQuery($sql , $limit);84 $result = WCF::getDB()->sendQuery($sql); 85 85 while ($row = WCF::getDB()->fetchArray($result)) { 86 86 $types[$row['messageType']] = $row['messageID']; … … 162 162 163 163 $this->loadDocuments($row['current'] + 1, min($row['total'], $row['current'] + 1 + $limit)); 164 164 165 165 // write to solr 166 166 $this->commit(); … … 184 184 'current' => 0, 185 185 'total' => 0, 186 'percent' => 0, 186 187 ); 187 188 } 188 189 189 190 // read current status 190 191 while ($row = WCF::getDB()->fetchArray($result)) { 191 $sql = 'SELECT typeName, 192 c 193 FROM ( 194 SELECT typeID, 195 COUNT(typeID) AS c 196 FROM wcf'.WCF_N.'_solr_index 197 GROUP BY typeID 198 ) x 199 INNER JOIN wcf'.WCF_N.'_searchable_message_type USING(typeID)'; 200 while ($row = WCF::getDB()->fetchArray($sql)) { 192 201 $typeName = $row['typeName']; 193 $status[$typeName]['current'] = $row[' messageID'];202 $status[$typeName]['current'] = $row['c']; 194 203 } 195 204 196 205 // read totals 197 foreach ($this->getTotals($type) as $typeName => $total) { 198 $status[$typeName]['total'] = $row['messageID']; 199 } 200 201 return $messages; 206 foreach ($this->getTotals($types, 'COUNT') as $typeName => $count) { 207 $percent = $count ? 100 / $count * $status[$typeName]['current'] : 0; 208 $status[$typeName]['total'] = $count; 209 } 210 211 return $status; 202 212 } 203 213 }
