Changeset 1186
- Timestamp:
- 06/26/10 20:41:41 (3 years ago)
- Location:
- solr
- Files:
-
- 3 modified
-
acptemplates/solr.tpl (modified) (4 diffs)
-
files/lib/acp/form/SolrForm.class.php (modified) (3 diffs)
-
files/lib/data/solr/SolrBridge.php (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
solr/acptemplates/solr.tpl
r1185 r1186 20 20 .statBarLabel { 21 21 margin-left: 410px; 22 } 22 } 23 23 /*]]>*/ 24 24 </style> 25 25 {/capture} 26 26 {include file='header'} 27 27 28 28 <div class="mainHeadline"> 29 <img src="{@RELATIVE_WCF_DIR}icon/s tatsL.png" alt="" />29 <img src="{@RELATIVE_WCF_DIR}icon/solrL.png" alt="" /> 30 30 <div class="headlineContainer"> 31 <h2>{lang}wcf.acp.s tats{/lang}</h2>31 <h2>{lang}wcf.acp.solr{/lang}</h2> 32 32 </div> 33 33 </div> … … 38 38 39 39 {if $results|isset && !$results|count} 40 <p class="error">{lang}wcf.acp.s tats.noResults{/lang}</p>40 <p class="error">{lang}wcf.acp.solr.noResults{/lang}</p> 41 41 {/if} 42 42 {* 43 <form method="post" action="index.php?form=S tats">43 <form method="post" action="index.php?form=Solr"> 44 44 <div class="border content"> 45 45 <div class="container-1"> 46 46 <fieldset> 47 <legend>{lang}wcf.acp.s tats.config{/lang}</legend>48 47 <legend>{lang}wcf.acp.solr.config{/lang}</legend> 48 49 49 <div class="formElement{if $errorField == 'username'} formError{/if}"> 50 50 <div class="formFieldLabel"> … … 60 60 </div> 61 61 </div> 62 62 63 63 {if $additionalFields|isset}{@$additionalFields}{/if} 64 64 </fieldset> 65 65 </div> 66 66 </div> 67 67 68 68 <div class="formSubmit"> 69 69 <input type="submit" accesskey="s" value="{lang}wcf.global.button.submit{/lang}" /> … … 78 78 <div class="container-1"> 79 79 <fieldset> 80 <legend>{lang}wcf.acp.s tats.results{/lang}</legend>81 80 <legend>{lang}wcf.acp.solr.results{/lang}</legend> 81 82 82 {foreach from=$results item=result key=$type} 83 83 <div class="formElement"> 84 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> 85 <div class="formField"> 86 <div class="statBar"><div style="width: {$result.percent|round}%;"></div></div> 87 <p class="statBarLabel"> 88 {$result.percent|round}% {#$result.current}/{#$result.total} 89 </p> 90 </div> 86 91 </div> 87 92 88 93 {/foreach} 89 94 </fieldset> -
solr/files/lib/acp/form/SolrForm.class.php
r1185 r1186 26 26 */ 27 27 public $activeMenuItem = 'wcf.acp.menu.link.solr.index'; 28 29 /**30 * Permission31 *32 * @var string33 */34 public $neededPermissions = 'admin.contest.canAddClass';35 28 36 29 … … 44 37 parent::readFormParameters(); 45 38 46 if (isset($_POST['t opic'])) $this->topic = StringUtil::trim($_POST['topic']);39 if (isset($_POST['type'])) $this->type = StringUtil::trim($_POST['type']); 47 40 } 48 41 … … 55 48 $this->bridge = new SolrBridge(); 56 49 $this->status = $this->bridge->getIndexStatus(); 57 } 58 59 /** 60 * @see Form::save() 61 */ 62 public function save() { 63 parent::save(); 64 65 // save 66 $this->contestClass = ContestClassEditor::create($this->topic, $this->text, 67 $this->parentClassID, $this->position, WCF::getLanguage()->getLanguageID()); 68 $this->saved(); 69 70 // reset values 71 $this->topic = $this->text = $this->parentClassID = ''; 72 $this->languageID = $this->position = 0; 73 74 // show success message 75 WCF::getTPL()->assign('success', true); 50 51 # demo call for crawling 52 # $this->bridge->doCrawl(array('lexicon'), 50); 76 53 } 77 54 -
solr/files/lib/data/solr/SolrBridge.php
r1185 r1186 7 7 /** 8 8 * 9 */ 9 */ 10 10 class SolrBridge { 11 12 /** 13 * 11 12 /** 13 * 14 14 * @var array<Apache_Solr_Document> 15 15 */ 16 16 protected $documents = array(); 17 17 18 18 /** 19 19 * … … 21 21 */ 22 22 protected $solr = null; 23 23 24 protected static $typeids = null; 25 24 26 /** 25 27 * 26 28 */ 27 29 public function __construct() { 28 30 29 31 // load search type objects 30 32 SearchEngine::getSearchTypes(); 31 33 32 34 $this->solr = new SolrService(); 33 35 } 34 36 35 37 /** 36 38 * 37 39 */ 38 40 protected function commit() { 39 $this->solr->addDocuments( $this->documents );40 $this->solr->commit();41 41 #$this->solr->addDocuments( $this->documents ); 42 #$this->solr->commit(); 43 42 44 // mark items as done 43 45 $sql = "INSERT IGNORE INTO 44 wcf".WCF_N."_solr_index 45 (typeID, messageID)"; 46 wcf".WCF_N."_solr_index 47 (typeID, messageID) 48 VALUES "; 46 49 foreach($this->documents as $doc) { 47 $sql .= ""; //TODO: mark as done 48 } 50 $typeID = $this->getTypeID($doc->messageType); 51 $sql .= "($typeID,".$doc->messageID."),"; 52 } 53 $sql = rtrim($sql, ','); 49 54 $result = WCF::getDB()->sendQuery($sql); 50 55 51 56 // reset array 52 57 $this->documents = array(); 53 54 $this->solr->optimize(); 55 } 56 58 59 // optimize solr index 60 #$this->solr->optimize(); 61 } 62 57 63 /** 58 64 * … … 67 73 if (!$doc->isAccessible()) continue; 68 74 if (!empty($sql)) $sql .= "\nUNION\n"; 69 75 70 76 // get field names 71 77 $messageIDFieldName = $doc->getIDFieldName(); 72 78 $messageIDFieldName = strpos($messageIDFieldName, '.') !== false ? $messageIDFieldName : "messageTable.".$messageIDFieldName; 73 74 $sql .= "( 79 80 $sql .= "( 75 81 SELECT ".$func."(".$messageIDFieldName.") AS messageID, 76 82 '".$type."' AS messageType … … 79 85 )"; 80 86 } 81 87 82 88 // send search query 83 89 $types = array(); … … 86 92 $types[$row['messageType']] = $row['messageID']; 87 93 } 88 94 89 95 return $types; 90 96 } 91 92 /** 93 * 94 */ 95 public function loadDocuments($type, $min, $max) { 97 98 private function cleanText($message) { 99 require_once(WCF_DIR.'lib/data/message/bbcode/MessageParser.class.php'); 100 101 // add cache resources 102 WCF::getCache()->addResource('bbcodes', WCF_DIR.'cache/cache.bbcodes.php', WCF_DIR.'lib/system/cache/CacheBuilderBBCodes.class.php'); 103 WCF::getCache()->addResource('smileys', WCF_DIR.'cache/cache.smileys.php', WCF_DIR.'lib/system/cache/CacheBuilderSmileys.class.php'); 104 105 $parser = MessageParser::getInstance(); 106 $parser->setOutputType('text/plain'); 107 $message = StringUtil::stripHTML($message); 108 return $parser->parse($message, false, false, true, false); 109 } 110 111 /** 112 * 113 * @return integer number of added documents 114 */ 115 public function loadDocuments($type, $min, $max, $limit) { 96 116 // get search type object 97 117 $doc = SearchEngine::$searchTypeObjects[$type]; 98 118 if (!$doc->isAccessible()) continue; 99 119 100 120 // get field names 101 121 $messageIDFieldName = $doc->getIDFieldName(); … … 106 126 $usernameFieldName = $doc->getUsernameFieldName(); 107 127 $timeFieldName = $doc->getTimeFieldName(); 108 109 $sql = "SELECT 128 129 $sql = "SELECT 110 130 '".$type."' AS messageType, 111 131 ".$messageIDFieldName." AS messageID, … … 118 138 ".$doc->getJoins()." 119 139 WHERE ".$messageIDFieldName." BETWEEN $min AND $max 120 ".(!empty($conditions[$type]) ? " ".(!empty($q) ? "AND" : "")." (".$conditions[$type].")" : "")."121 GROUP BY messageID";140 GROUP BY messageID 141 ORDER BY messageID ASC"; 122 142 123 143 $result = WCF::getDB()->sendQuery($sql, $limit); 144 $i = 0; 124 145 while ($row = WCF::getDB()->fetchArray($result)) { 146 $row['message'] = $this->cleanText($row['message']); 125 147 $this->addDocument($row); 126 } 127 } 128 148 $i++; 149 } 150 return $i; 151 } 152 129 153 /** 130 154 * … … 142 166 } 143 167 } 144 168 145 169 $this->documents[] = $part; 146 170 } 147 148 /** 149 * 150 */ 151 public function doCrawl($types, $limit) { 152 foreach($this->getIndexStatus($types) as $typeName => $status) { 153 171 172 /** 173 * 174 */ 175 public function doCrawl($types = null, $limit = null) { 176 177 // get types 178 $types = is_array($types) ? $types : $this->getSearchTypes(); 179 180 $i = 0; 181 182 foreach($this->getIndexStatus($types, 'MAX') as $type => $status) { 183 154 184 // nothing to do? 155 if($ row['total'] == $row['current']) {185 if($status['total'] == $status['current']) { 156 186 continue; 157 187 } 158 188 // get search type object 189 $doc = SearchEngine::$searchTypeObjects[$type]; 190 if (!$doc->isAccessible()) continue; 191 159 192 if (!isset(SearchEngine::$searchTypeObjects[$type])) { 160 193 throw new SystemException('unknown search type '.$type, 101001); 161 194 } 195 $j = $this->loadDocuments($type, $status['current'] + 1, $status['total'], $limit); 196 if($j) { 197 $i += $j; 198 199 // write to solr 200 $this->commit(); 201 } 202 } 203 204 return $i; 205 } 206 207 private function getTypeID($type) { 208 209 if(self::$typeids === null) { 210 self::$typeids = array(); 211 212 $sql = 'SELECT * 213 FROM wcf'.WCF_N.'_searchable_message_type'; 214 $result = WCF::getDB()->sendQuery($sql); 215 while ($row = WCF::getDB()->fetchArray($result)) { 216 self::$typeids[$row['typeName']] = $row['typeID']; 217 } 218 } 219 return self::$typeids[$type]; 220 } 221 222 private function getSearchTypes() { 223 $types = SearchEngine::getSearchTypes(); 224 $return = array(); 225 foreach($types as $type) { 226 $doc = SearchEngine::$searchTypeObjects[$type]; 227 if (!$doc->isAccessible()) continue; 162 228 163 $this->loadDocuments($row['current'] + 1, min($row['total'], $row['current'] + 1 + $limit)); 164 165 // write to solr 166 $this->commit(); 167 } 168 } 169 170 /** 171 * 172 */ 173 public function getIndexStatus($types = null) { 174 229 $return[] = $type; 230 } 231 return $return; 232 } 233 234 /** 235 * 236 */ 237 public function getIndexStatus($types = null, $func = 'COUNT') { 238 175 239 // read available types 176 240 $status = array(); 177 241 178 242 // get types 179 $types = is_array($types) ? $types : SearchEngine::getSearchTypes();180 243 $types = is_array($types) ? $types : $this->getSearchTypes(); 244 181 245 // set counters to zero 182 246 foreach ($types as $type) { … … 187 251 ); 188 252 } 189 253 190 254 // read current status 191 255 $sql = 'SELECT typeName, 192 256 c 193 257 FROM ( 194 SELECT typeID, 195 COUNT(typeID) AS c196 FROM wcf'.WCF_N.'_solr_index 258 SELECT typeID, 259 '.$func.'(messageID) AS c 260 FROM wcf'.WCF_N.'_solr_index 197 261 GROUP BY typeID 198 262 ) x 199 INNER JOIN wcf'.WCF_N.'_searchable_message_type USING(typeID)'; 200 while ($row = WCF::getDB()->fetchArray($sql)) { 263 INNER JOIN wcf'.WCF_N.'_searchable_message_type USING(typeID) 264 WHERE typeName IN ("'.implode('","', $types).'")'; 265 $result = WCF::getDB()->sendQuery($sql); 266 while ($row = WCF::getDB()->fetchArray($result)) { 201 267 $typeName = $row['typeName']; 202 268 $status[$typeName]['current'] = $row['c']; … … 204 270 205 271 // read totals 206 foreach ($this->getTotals($types, 'COUNT') as $typeName => $count) { 207 $percent = $count ? 100 / $count * $status[$typeName]['current'] : 0; 272 foreach ($this->getTotals($types, $func) as $typeName => $count) { 208 273 $status[$typeName]['total'] = $count; 209 } 210 274 $status[$typeName]['percent'] = $count ? 100 / $count * $status[$typeName]['current'] : 0; 275 } 276 211 277 return $status; 212 278 }
