Changeset 1185

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

it is possible to display solr status :)

Location:
solr
Files:
1 added
5 modified

Legend:

Unmodified
Added
Removed
  • solr/acptemplates/solr.tpl

    r1184 r1185  
     1{capture append='specialStyles'} 
     2<style type="text/css"> 
     3/*<![CDATA[*/ 
     4.statBar { 
     5        text-align: left; 
     6        padding: 1px; 
     7        background-color: #fff; 
     8        border: 1px solid #8da4b7; 
     9        float: left; 
     10        width: 400px; 
     11} 
     12 
     13.statBar div { 
     14        font-size: 6px; /* needed for correct usage-bar display in IE-browsers */ 
     15        background-color: #0c0; 
     16        border-bottom: 6px solid #0a0; 
     17        height: 6px; 
     18} 
     19 
     20.statBarLabel { 
     21        margin-left: 410px; 
     22}                        
     23/*]]>*/ 
     24</style> 
     25{/capture} 
    126{include file='header'} 
    2  
     27         
    328<div class="mainHeadline"> 
    4         <img src="{@RELATIVE_WCF_DIR}icon/contestClass{@$action|ucfirst}L.png" alt="" /> 
     29        <img src="{@RELATIVE_WCF_DIR}icon/statsL.png" alt="" /> 
    530        <div class="headlineContainer"> 
    6                 <h2>{lang}wcf.acp.contest.class.{@$action}{/lang}</h2> 
     31                <h2>{lang}wcf.acp.stats{/lang}</h2> 
    732        </div> 
    833</div> 
     
    1237{/if} 
    1338 
    14 {if $success|isset} 
    15         <p class="success">{lang}wcf.acp.contest.class.{@$action}.success{/lang}</p>     
     39{if $results|isset && !$results|count} 
     40        <p class="error">{lang}wcf.acp.stats.noResults{/lang}</p> 
    1641{/if} 
    17  
    18 <div class="contentHeader"> 
    19         <div class="largeButtons"> 
    20                 <ul><li><a href="index.php?page=ContestClassList&amp;packageID={@PACKAGE_ID}{@SID_ARG_2ND}" title="{lang}wcf.acp.menu.link.contest.class{/lang}"><img src="{@RELATIVE_WCF_DIR}icon/contestClassM.png" alt="" /> <span>{lang}wcf.acp.menu.link.contest.class{/lang}</span></a></li></ul> 
    21         </div> 
    22 </div> 
    23  
    24 <form method="post" action="index.php?form=ContestClass{@$action|ucfirst}"> 
     42{* 
     43<form  method="post" action="index.php?form=Stats"> 
    2544        <div class="border content"> 
    2645                <div class="container-1"> 
    2746                        <fieldset> 
    28                                 <legend>{lang}wcf.acp.contest.class.data{/lang}</legend> 
     47                                <legend>{lang}wcf.acp.stats.config{/lang}</legend> 
    2948                                 
    30                                 {if $action == 'edit'} 
    31                                         <div class="formElement" id="languageIDDiv"> 
    32                                                 <div class="formFieldLabel"> 
    33                                                         <label for="languageID">{lang}wcf.user.language{/lang}</label> 
    34                                                 </div> 
    35                                                 <div class="formField"> 
    36                                                         <select name="languageID" id="languageID" onchange="location.href='index.php?form=ContestClassEdit&amp;classID={@$classID}&amp;languageID=' + this.value + '&amp;packageID={@PACKAGE_ID}{@SID_ARG_2ND}'"> 
    37                                                                 {foreach from=$languages key=key item=language} 
    38                                                                         <option value="{@$key}"{if $key == $languageID} selected="selected"{/if}> 
    39                                                                                 {lang}wcf.global.language.{@$language}{/lang} 
    40                                                                         </option> 
    41                                                                 {/foreach}                                               
    42                                                         </select> 
    43                                                 </div> 
    44                                         </div> 
    45                                 {/if} 
    46                                  
    47                                 <div class="formElement{if $errorField == 'topic'} formError{/if}" id="topicDiv"> 
     49                                <div class="formElement{if $errorField == 'username'} formError{/if}"> 
    4850                                        <div class="formFieldLabel"> 
    49                                                 <label for="topic">{lang}wcf.acp.contest.class.title{/lang}</label> 
     51                                                <label for="username">{lang}wcf.user.username{/lang}</label> 
    5052                                        </div> 
    5153                                        <div class="formField"> 
    52                                                 <input type="text" class="inputText" id="topic" name="topic" value="{$topic}" /> 
    53                                                 {if $errorField == 'topic'} 
     54                                                <input type="text" class="inputText" id="username" name="username" value="" /> 
     55                                                {if $errorField == 'username'} 
    5456                                                        <p class="innerError"> 
    55                                                                 {if $errorType == 'empty'}{lang}wcf.global.error.empty{/lang}{/if} 
     57                                                                {if $errorType == 'notFound'}{lang}wcf.user.error.username.notFound{/lang}{/if} 
    5658                                                        </p> 
    5759                                                {/if} 
    5860                                        </div> 
    5961                                </div> 
    60                                                          
    61                                 <div class="formElement{if $errorField == 'text'} formError{/if}" id="textDiv"> 
    62                                         <div class="formFieldLabel"> 
    63                                                 <label for="text">{lang}wcf.acp.contest.class.description{/lang}</label> 
    64                                         </div> 
    65                                         <div class="formField"> 
    66                                                 <textarea name="text" id="text" rows="7" cols="40">{$text}</textarea> 
    67                                                 {if $errorField == 'text'} 
    68                                                         <p class="innerError"> 
    69                                                                 {if $errorType == 'empty'}{lang}wcf.global.error.empty{/lang}{/if} 
    70                                                         </p> 
    71                                                 {/if} 
    72                                         </div> 
    73                                 </div> 
     62                                 
     63                                {if $additionalFields|isset}{@$additionalFields}{/if} 
    7464                        </fieldset> 
    75                                                  
    76                         {if $additionalFields|isset}{@$additionalFields}{/if} 
    7765                </div> 
    7866        </div> 
    79  
     67                 
    8068        <div class="formSubmit"> 
    8169                <input type="submit" accesskey="s" value="{lang}wcf.global.button.submit{/lang}" /> 
    8270                <input type="reset" accesskey="r" value="{lang}wcf.global.button.reset{/lang}" /> 
    8371                <input type="hidden" name="packageID" value="{@PACKAGE_ID}" /> 
    84                 {if $classID|isset}<input type="hidden" name="classID" value="{@$classID}" />{/if} 
    85                 {@SID_INPUT_TAG} 
     72                {@SID_INPUT_TAG} 
    8673        </div> 
    8774</form> 
     75*} 
     76{if $results|isset && $results|count} 
     77        <div class="border content"> 
     78                <div class="container-1"> 
     79                        <fieldset> 
     80                                <legend>{lang}wcf.acp.stats.results{/lang}</legend> 
     81         
     82                                {foreach from=$results item=result key=$type} 
     83                                        <div class="formElement"> 
     84                                                <p class="formFieldLabel">{$type}</p> 
     85                                                <div class="formField"><div class="statBar"><div style="width: {$result.percent|round}%;"></div></div><p class="statBarLabel">{#$result.current}/{#$result.total}</p></div> 
     86                                        </div> 
     87                                 
     88                                {/foreach} 
     89                        </fieldset> 
     90                </div> 
     91        </div> 
     92{/if} 
    8893 
    8994{include file='footer'} 
  • solr/files/lib/acp/form/SolrForm.class.php

    r1184 r1185  
    2525         * @var string 
    2626         */ 
    27         public $activeMenuItem = 'wcf.acp.menu.link.contest.class'; 
     27        public $activeMenuItem = 'wcf.acp.menu.link.solr.index'; 
    2828         
    2929        /** 
     
    4848 
    4949        /** 
    50          * @see Form::validate() 
     50         * @see Page::readData() 
    5151         */ 
    52         public function validate() { 
    53                 parent::validate(); 
     52        public function readData() { 
     53                parent::readData(); 
     54 
     55                $this->bridge = new SolrBridge(); 
     56                $this->status = $this->bridge->getIndexStatus(); 
    5457        } 
    5558 
     
    8083 
    8184                WCF::getTPL()->assign(array( 
    82                         'topic' => $this->topic, 
    83                         'text' => $this->text, 
    84                         'contestClass' => $this->contestClass, 
    85                         'languageID' => $this->languageID, 
    86                         'class' => $this->contestClass, 
    87                         'action' => 'add' 
     85                        'results' => $this->status, 
    8886                )); 
    8987        } 
  • 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} 
  • solr/files/lib/data/solr/SolrService.php

    r1183 r1185  
    11<?php 
    2 require_once(BASEDIR.'libs/solr/Service.php'); 
     2require_once(WCF_DIR.'lib/data/solr/Service.php'); 
    33 
    44/** 
     
    66 */ 
    77class SolrService extends Apache_Solr_Service { 
    8         public function __construct($url) { 
    9                 $path = parse_url($url); 
    10                  
     8        public function __construct() { 
     9                $path = parse_url(SOLR_URL); 
    1110                parent::__construct($path['host'], isset($path['port']) ? $path['port'] : 80, $path['path']); 
    1211        } 
  • solr/package.xml

    r1184 r1185  
    2626                <templates>templates.tar</templates> 
    2727                <acptemplates>acptemplates.tar</acptemplates> 
     28                <sql>install.sql</sql> 
    2829                 
    2930                <!-- config --> 
     
    3132                <acpmenu>acpmenu.xml</acpmenu> 
    3233                <options>options.xml</options> 
    33                 <groupoptions>groupoptions.xml</groupoptions> 
    3434                <pagemenu>pagemenu.xml</pagemenu> 
    3535                <pagelocation>pagelocation.xml</pagelocation>