Show
Ignore:
Timestamp:
06/26/10 13:29:33 (3 years ago)
Author:
d0nut
Message:

it is possible to display solr status :)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • solr/files/lib/data/solr/SolrBridge.php

    r1184 r1185  
    11<?php 
     2// wcf imports 
     3require_once(WCF_DIR.'lib/data/message/search/SearchEngine.class.php'); 
     4require_once(WCF_DIR.'lib/data/solr/SolrService.php'); 
     5 
    26 
    37/** 
     
    2428         
    2529                // 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(); 
    3033        } 
    3134         
     
    4043                $sql = "INSERT IGNORE INTO 
    4144                                        wcf".WCF_N."_solr_index 
    42                                         (typeName, messageID)"; 
     45                                        (typeID, messageID)"; 
    4346                foreach($this->documents as $doc) { 
    4447                        $sql .= ""; //TODO: mark as done 
     
    5558         * 
    5659         */ 
    57         protected function getTotals(array $types) { 
     60        protected function getTotals(array $types, $func) { 
    5861 
    5962                $sql = ''; 
     
    7073                         
    7174                        $sql .= "(       
    72                                 SELECT          MAX(".$messageIDFieldName.") AS messageID, 
     75                                SELECT          ".$func."(".$messageIDFieldName.") AS messageID, 
    7376                                                '".$type."' AS messageType 
    7477                                FROM            ".$doc->getTableName()." messageTable 
    7578                                                ".$doc->getJoins()." 
    76                                 WHERE           1 
    77                                                 ".(!empty($conditions[$type]) ? " ".(!empty($q) ? "AND" : "")." (".$conditions[$type].")" : "")." 
    78                                 GROUP BY        messageID 
    7979                        )"; 
    8080                } 
     
    8282                // send search query 
    8383                $types = array(); 
    84                 $result = WCF::getDB()->sendQuery($sql, $limit); 
     84                $result = WCF::getDB()->sendQuery($sql); 
    8585                while ($row = WCF::getDB()->fetchArray($result)) { 
    8686                        $types[$row['messageType']] = $row['messageID']; 
     
    162162                         
    163163                        $this->loadDocuments($row['current'] + 1, min($row['total'], $row['current'] + 1 + $limit)); 
    164                  
     164 
    165165                        // write to solr 
    166166                        $this->commit(); 
     
    184184                                'current' => 0, 
    185185                                'total' => 0, 
     186                                'percent' => 0, 
    186187                        ); 
    187188                } 
    188189                 
    189190                // 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)) { 
    192201                        $typeName = $row['typeName']; 
    193                         $status[$typeName]['current'] = $row['messageID']; 
     202                        $status[$typeName]['current'] = $row['c']; 
    194203                } 
    195204 
    196205                // 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; 
    202212        } 
    203213}