Changeset 1185
- Timestamp:
- 06/26/10 13:29:33 (3 years ago)
- Location:
- solr
- Files:
-
- 1 added
- 5 modified
-
acptemplates/solr.tpl (modified) (2 diffs)
-
files/lib/acp/form/SolrForm.class.php (modified) (3 diffs)
-
files/lib/data/solr/SolrBridge.php (modified) (8 diffs)
-
files/lib/data/solr/SolrService.php (modified) (2 diffs)
-
install.sql (added)
-
package.xml (modified) (2 diffs)
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} 1 26 {include file='header'} 2 27 3 28 <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="" /> 5 30 <div class="headlineContainer"> 6 <h2>{lang}wcf.acp. contest.class.{@$action}{/lang}</h2>31 <h2>{lang}wcf.acp.stats{/lang}</h2> 7 32 </div> 8 33 </div> … … 12 37 {/if} 13 38 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> 16 41 {/if} 17 18 <div class="contentHeader"> 19 <div class="largeButtons"> 20 <ul><li><a href="index.php?page=ContestClassList&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"> 25 44 <div class="border content"> 26 45 <div class="container-1"> 27 46 <fieldset> 28 <legend>{lang}wcf.acp. contest.class.data{/lang}</legend>47 <legend>{lang}wcf.acp.stats.config{/lang}</legend> 29 48 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&classID={@$classID}&languageID=' + this.value + '&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}"> 48 50 <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> 50 52 </div> 51 53 <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'} 54 56 <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} 56 58 </p> 57 59 {/if} 58 60 </div> 59 61 </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} 74 64 </fieldset> 75 76 {if $additionalFields|isset}{@$additionalFields}{/if}77 65 </div> 78 66 </div> 79 67 80 68 <div class="formSubmit"> 81 69 <input type="submit" accesskey="s" value="{lang}wcf.global.button.submit{/lang}" /> 82 70 <input type="reset" accesskey="r" value="{lang}wcf.global.button.reset{/lang}" /> 83 71 <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} 86 73 </div> 87 74 </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} 88 93 89 94 {include file='footer'} -
solr/files/lib/acp/form/SolrForm.class.php
r1184 r1185 25 25 * @var string 26 26 */ 27 public $activeMenuItem = 'wcf.acp.menu.link. contest.class';27 public $activeMenuItem = 'wcf.acp.menu.link.solr.index'; 28 28 29 29 /** … … 48 48 49 49 /** 50 * @see Form::validate()50 * @see Page::readData() 51 51 */ 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(); 54 57 } 55 58 … … 80 83 81 84 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, 88 86 )); 89 87 } -
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 } -
solr/files/lib/data/solr/SolrService.php
r1183 r1185 1 1 <?php 2 require_once( BASEDIR.'libs/solr/Service.php');2 require_once(WCF_DIR.'lib/data/solr/Service.php'); 3 3 4 4 /** … … 6 6 */ 7 7 class 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); 11 10 parent::__construct($path['host'], isset($path['port']) ? $path['port'] : 80, $path['path']); 12 11 } -
solr/package.xml
r1184 r1185 26 26 <templates>templates.tar</templates> 27 27 <acptemplates>acptemplates.tar</acptemplates> 28 <sql>install.sql</sql> 28 29 29 30 <!-- config --> … … 31 32 <acpmenu>acpmenu.xml</acpmenu> 32 33 <options>options.xml</options> 33 <groupoptions>groupoptions.xml</groupoptions>34 34 <pagemenu>pagemenu.xml</pagemenu> 35 35 <pagelocation>pagelocation.xml</pagelocation>
