Index: trunk/extensions/SolrStore/SolrConnector.php |
— | — | @@ -1,9 +1,9 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | 4 | * Early versions of the extension had to include SolrConnector.php. |
5 | | - * |
| 5 | + * |
6 | 6 | * This file keeps backward compatibility for a while. |
7 | | - * |
| 7 | + * |
8 | 8 | * @ingroup SolrStore |
9 | 9 | * @file |
10 | 10 | */ |
Index: trunk/extensions/SolrStore/SolrStore.i18n.php |
— | — | @@ -16,6 +16,14 @@ |
17 | 17 | 'searchFieldSets-title' => 'SolrSearch: SearchSet Select', |
18 | 18 | ); |
19 | 19 | |
| 20 | +$messages['qqq'] = array( |
| 21 | + 'solrconnector-desc' => '{{desc}}', |
| 22 | + 'solrsearch' => 'The title of the Special:SolrSearch page as appearing in Special:SpecialPages. Should probably the same as message \'\'searchFieldSets\'\'', |
| 23 | + 'searchFieldSets' => 'The pagetitle (heading) of the Special:SolrSearch page', |
| 24 | + 'searchFieldSets-select' => 'A message', |
| 25 | + 'searchFieldSets-title' => 'The title of the Special:SolrSearch page', |
| 26 | +); |
| 27 | + |
20 | 28 | $messages['de'] = array( |
21 | 29 | 'solrsearch' => 'SolrSuche', |
22 | 30 | 'searchFieldSets' => 'SolrSuche', |
Index: trunk/extensions/SolrStore/SolrStore.php |
— | — | @@ -30,7 +30,7 @@ |
31 | 31 | define( 'SC_VERSION', '0.5 Beta' ); |
32 | 32 | |
33 | 33 | // register the extension |
34 | | -//TODO: Add other authors here and in the file header |
| 34 | +// TODO: Add other authors here and in the file header |
35 | 35 | $wgExtensionCredits[defined( 'SEMANTIC_EXTENSION_TYPE' ) ? 'semantic' : 'other'][] = array( |
36 | 36 | 'path' => __FILE__, |
37 | 37 | 'name' => 'SolrStore', |
— | — | @@ -72,7 +72,6 @@ |
73 | 73 | |
74 | 74 | // Solr Configuration |
75 | 75 | $wgSolrTalker = new SolrTalker(); |
76 | | -if ( !isset( $wgSolrUrl ) ){ |
77 | | - //Url to the Solr Server |
78 | | - $wgSolrUrl = 'http://svbosofixwiki:8180/solr'; |
79 | | -} |
| 76 | + |
| 77 | +$wgSolrUrl = 'http://127.0.0.1:8080/solr'; |
| 78 | +$wgSolrFields = array(); |
Index: trunk/extensions/SolrStore/SolrTalker.php |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | 4 | * File holding the SolrTalker class |
5 | | - * |
| 5 | + * |
6 | 6 | * @ingroup SolrStore |
7 | 7 | * @file |
8 | 8 | * @author Simon Bachenberg |
— | — | @@ -9,107 +9,107 @@ |
10 | 10 | |
11 | 11 | /** |
12 | 12 | * This class should do all the talk to the Solr server. |
13 | | - * |
| 13 | + * |
14 | 14 | * @ingroup SolrStore |
15 | 15 | */ |
16 | 16 | class SolrTalker { |
17 | 17 | |
18 | | - private $header = array("Content-type:text/xml; charset=utf-8"); |
| 18 | + private $header = array( "Content-type:text/xml; charset=utf-8" ); |
19 | 19 | private $schema; |
20 | 20 | |
21 | 21 | /** |
22 | 22 | * Get the Schema from SOLR as XML |
23 | 23 | * This Includes all Dynamic Fields |
24 | | - * |
| 24 | + * |
25 | 25 | * @return type $xml schema |
26 | 26 | */ |
27 | 27 | public function getSchema() { |
28 | 28 | global $wgSolrUrl; |
29 | | - $xml = $this->solrSend($wgSolrUrl . '/admin/luke?numTerms=0'); |
| 29 | + $xml = $this->solrSend( $wgSolrUrl . '/admin/luke?numTerms=0' ); |
30 | 30 | |
31 | 31 | try { |
32 | 32 | $this->schema = $xml; |
33 | | - } catch (Exception $exc) { |
| 33 | + } catch ( Exception $exc ) { |
34 | 34 | return false; |
35 | 35 | } |
36 | 36 | |
37 | 37 | return $this->schema; |
38 | 38 | } |
39 | 39 | |
40 | | - public function encodeSolr($query) { |
41 | | - //Using the urlencode from php doenst work!?, so we need to do it our self |
42 | | - $query = str_replace('"', '%22', trim($query)); |
43 | | - $query = str_replace(' ', '+', $query); |
44 | | - $query = str_replace('ü', '%FC', $query); |
45 | | - $query = str_replace('Ü', '%DC', $query); |
46 | | - $query = str_replace('ö', '%F6', $query); |
47 | | - $query = str_replace('Ö', '%D6', $query); |
48 | | - $query = str_replace('ä', '%E4', $query); |
49 | | - $query = str_replace('ä', '%C4', $query); |
| 40 | + public function encodeSolr( $query ) { |
| 41 | + // Using the urlencode from php doenst work!?, so we need to do it our self |
| 42 | + $query = str_replace( '"', '%22', trim( $query ) ); |
| 43 | + $query = str_replace( ' ', '+', $query ); |
| 44 | + $query = str_replace( 'ü', '%FC', $query ); |
| 45 | + $query = str_replace( 'Ü', '%DC', $query ); |
| 46 | + $query = str_replace( 'ö', '%F6', $query ); |
| 47 | + $query = str_replace( 'Ö', '%D6', $query ); |
| 48 | + $query = str_replace( 'ä', '%E4', $query ); |
| 49 | + $query = str_replace( 'ä', '%C4', $query ); |
50 | 50 | return $query; |
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
54 | 54 | * Perform a SolrSearch |
55 | | - * |
| 55 | + * |
56 | 56 | * @global type $wgSolrUrl |
57 | 57 | * @param type $query - Search Term |
58 | 58 | * @param type $start - Offset |
59 | 59 | * @param type $end - Limit |
60 | | - * @return type $xml - Solr Result as XML |
61 | | - * |
| 60 | + * @return type $xml - Solr Result as XML |
| 61 | + * |
62 | 62 | */ |
63 | | - public function solrQuery($query, $start, $end, $highlight=false, $score=false) { |
| 63 | + public function solrQuery( $query, $start, $end, $highlight = false, $score = false ) { |
64 | 64 | global $wgSolrUrl; |
65 | | - $query = trim($query); |
66 | | - if (empty($query)) { |
| 65 | + $query = trim( $query ); |
| 66 | + if ( empty( $query ) ) { |
67 | 67 | $query = '*'; |
68 | 68 | } |
69 | | - $url = $wgSolrUrl . '/select?q=' . $query . '&start=' . $start . '&rows=' . $end; //. '&fl=*%2Cscore'; No Score for now, ther seems to be a BUG |
70 | | - if ($highlight) { |
71 | | - $url.='&hl=on&hl.fl=*'; |
| 69 | + $url = $wgSolrUrl . '/select?q=' . $query . '&start=' . $start . '&rows=' . $end; // . '&fl=*%2Cscore'; No Score for now, ther seems to be a BUG |
| 70 | + if ( $highlight ) { |
| 71 | + $url .= '&hl=on&hl.fl=*'; |
72 | 72 | } |
73 | | - if ($score) { |
74 | | - $url.='&fl=*%2Cscore'; |
| 73 | + if ( $score ) { |
| 74 | + $url .= '&fl=*%2Cscore'; |
75 | 75 | } |
76 | | - return $this->solrSend($url); |
| 76 | + return $this->solrSend( $url ); |
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
80 | 80 | * Find the real name of the Field in the SOlr schema |
81 | | - * |
| 81 | + * |
82 | 82 | * @param type $searchField |
83 | 83 | * @param type $sort = ASC or DESC |
84 | 84 | * @return type Name of the Field you are searching for |
85 | 85 | */ |
86 | | - public function findField($searchField, $sort = 'ASC') { |
| 86 | + public function findField( $searchField, $sort = 'ASC' ) { |
87 | 87 | $xml = $this->getSchema(); |
88 | | - //$searchField = trim($searchField); |
89 | | - $searchField = str_replace(' ', '_', trim($searchField)); // Trim and Replace all Spaces with underscore for better matching |
| 88 | + // $searchField = trim($searchField); |
| 89 | + $searchField = str_replace( ' ', '_', trim( $searchField ) ); // Trim and Replace all Spaces with underscore for better matching |
90 | 90 | $result = false; |
91 | 91 | $stop = false; |
92 | 92 | |
93 | | - //TODO: Decide on ASC + DESC parameter for Max or Min Sort Field |
94 | | - foreach ($xml->lst as $item) { |
95 | | - if ($item['name'] == 'fields') { |
96 | | - foreach ($item->lst as $field) { |
97 | | - if (count($field) > 2) { |
98 | | - $dynamicBase = substr($field->str[2], 1); // Get The dynamicbase of the Field eg. "*_dtmax" |
99 | | - $newField = str_replace($dynamicBase, '', $field['name']); // Get the Fieldname without the dynamicbase |
100 | | - if (strcasecmp(str_replace(' ', '_', $newField), $searchField) == 0) { // Replace all Spaces with underscore for better matching |
101 | | - if (stripos($dynamicBase, 'max') && stripos($sort, 'desc')) { |
| 93 | + // TODO: Decide on ASC + DESC parameter for Max or Min Sort Field |
| 94 | + foreach ( $xml->lst as $item ) { |
| 95 | + if ( $item['name'] == 'fields' ) { |
| 96 | + foreach ( $item->lst as $field ) { |
| 97 | + if ( count( $field ) > 2 ) { |
| 98 | + $dynamicBase = substr( $field->str[2], 1 ); // Get The dynamicbase of the Field eg. "*_dtmax" |
| 99 | + $newField = str_replace( $dynamicBase, '', $field['name'] ); // Get the Fieldname without the dynamicbase |
| 100 | + if ( strcasecmp( str_replace( ' ', '_', $newField ), $searchField ) == 0 ) { // Replace all Spaces with underscore for better matching |
| 101 | + if ( stripos( $dynamicBase, 'max' ) && stripos( $sort, 'desc' ) ) { |
102 | 102 | // For Descending Sorting use the MaX value Field |
103 | | - continue 2; //we got the right Field Stop it! |
104 | | - } else if (stripos($dynamicBase, 'min') && stripos($sort, 'asc')) { |
105 | | - // For Ascending Sorting use the MIN value Field |
106 | | - continue 2; //we got the right Field Stop it! |
| 103 | + continue 2; // we got the right Field Stop it! |
| 104 | + } else if ( stripos( $dynamicBase, 'min' ) && stripos( $sort, 'asc' ) ) { |
| 105 | + // For Ascending Sorting use the MIN value Field |
| 106 | + continue 2; // we got the right Field Stop it! |
107 | 107 | } |
108 | | - } else if (strcasecmp(str_replace(' ', '_', $field['name']), $searchField) == 0) { // Replace all Spaces with underscore for better matching |
109 | | - $result = trim($searchField); |
| 108 | + } else if ( strcasecmp( str_replace( ' ', '_', $field['name'] ), $searchField ) == 0 ) { // Replace all Spaces with underscore for better matching |
| 109 | + $result = trim( $searchField ); |
110 | 110 | } |
111 | 111 | } else { |
112 | | - if (strcasecmp(trim($field['name']), trim($searchField)) == 0) { |
113 | | - $result = trim($field['name']); |
| 112 | + if ( strcasecmp( trim( $field['name'] ), trim( $searchField ) ) == 0 ) { |
| 113 | + $result = trim( $field['name'] ); |
114 | 114 | } |
115 | 115 | } |
116 | 116 | } |
— | — | @@ -120,20 +120,20 @@ |
121 | 121 | |
122 | 122 | /** |
123 | 123 | * Check the Query for existing fields |
124 | | - * |
| 124 | + * |
125 | 125 | * @param type $queryStr - Wiki QueryString |
126 | 126 | * @return type $queryStr - Solr QueryString |
127 | 127 | */ |
128 | | - public function queryChecker($queryStr) { |
129 | | - $queryStr = str_replace('=', ':', $queryStr); // Now you can use = insted : for querying Fields |
130 | | - if (strpos($queryStr, ':') !== false) { |
131 | | - $queryParts = explode(" ", $queryStr); //Split on Spaces and Search for Fields |
| 128 | + public function queryChecker( $queryStr ) { |
| 129 | + $queryStr = str_replace( '=', ':', $queryStr ); // Now you can use = insted : for querying Fields |
| 130 | + if ( strpos( $queryStr, ':' ) !== false ) { |
| 131 | + $queryParts = explode( " ", $queryStr ); // Split on Spaces and Search for Fields |
132 | 132 | $queryStr = ''; |
133 | | - foreach ($queryParts as $value) { |
134 | | - if (strpos($value, ':') !== false) { //Value conatins a ":" ? |
135 | | - $parts = explode(':', $value); //Split the Query part in Key (Parts[0]) and Value (Parts[1]) |
136 | | - $solrField = $this->findField($parts[0]); //Search for a Solr Field for the Key |
137 | | - if ($solrField) { |
| 133 | + foreach ( $queryParts as $value ) { |
| 134 | + if ( strpos( $value, ':' ) !== false ) { // Value conatins a ":" ? |
| 135 | + $parts = explode( ':', $value ); // Split the Query part in Key (Parts[0]) and Value (Parts[1]) |
| 136 | + $solrField = $this->findField( $parts[0] ); // Search for a Solr Field for the Key |
| 137 | + if ( $solrField ) { |
138 | 138 | $queryStr = $queryStr . ' ' . $solrField . ':' . $parts[1]; |
139 | 139 | } else { |
140 | 140 | $queryStr = $queryStr . ' ' . $parts[0] . ' ' . $parts[1]; |
— | — | @@ -144,105 +144,105 @@ |
145 | 145 | } |
146 | 146 | } |
147 | 147 | |
148 | | - return $queryStr = $this->encodeSolr($queryStr); |
| 148 | + return $queryStr = $this->encodeSolr( $queryStr ); |
149 | 149 | } |
150 | 150 | |
151 | 151 | /** |
152 | 152 | * Transform a Wiki Query to a Solr Query |
153 | 153 | * TODO: Do more Wiki2Solr transformation |
154 | | - * |
| 154 | + * |
155 | 155 | * @param type $queryStr - Wiki QueryString |
156 | 156 | * @return type $queryStr - Solr QueryString |
157 | 157 | */ |
158 | | - public function parseSolrQuery($queryStr) { |
159 | | - //TODO: Parse the QueryString to make it work in Solr |
160 | | - $queryParts = explode("[[", $queryStr); |
| 158 | + public function parseSolrQuery( $queryStr ) { |
| 159 | + // TODO: Parse the QueryString to make it work in Solr |
| 160 | + $queryParts = explode( "[[", $queryStr ); |
161 | 161 | |
162 | | - //Clean the queryStr |
| 162 | + // Clean the queryStr |
163 | 163 | $queryStr = ''; |
164 | | - foreach ($queryParts as $part) { |
165 | | - if (stripos($part, '::')) { |
166 | | - $parts = split('::', $part); //Split the Query part in Key (Parts[0]) and Value (Parts[1]) |
167 | | - $parts[0] = $this->findField($parts[0]); //Search for a Solr Field for the Key |
168 | | - $queryStr = $queryStr . ' ' . $parts[0] . ':' . $parts[1]; //Build Querystring |
169 | | - } elseif (stripos($part, ':')) { |
170 | | - $queryStr = $queryStr . ' category' . substr($part, stripos($part, ':')); |
| 164 | + foreach ( $queryParts as $part ) { |
| 165 | + if ( stripos( $part, '::' ) ) { |
| 166 | + $parts = split( '::', $part ); // Split the Query part in Key (Parts[0]) and Value (Parts[1]) |
| 167 | + $parts[0] = $this->findField( $parts[0] ); // Search for a Solr Field for the Key |
| 168 | + $queryStr = $queryStr . ' ' . $parts[0] . ':' . $parts[1]; // Build Querystring |
| 169 | + } elseif ( stripos( $part, ':' ) ) { |
| 170 | + $queryStr = $queryStr . ' category' . substr( $part, stripos( $part, ':' ) ); |
171 | 171 | } else { |
172 | 172 | $queryStr = $queryStr . $part; |
173 | 173 | } |
174 | 174 | } |
175 | | - $queryStr = str_replace('[', '', $queryStr); |
176 | | - $queryStr = str_replace(']', '', $queryStr); |
| 175 | + $queryStr = str_replace( '[', '', $queryStr ); |
| 176 | + $queryStr = str_replace( ']', '', $queryStr ); |
177 | 177 | |
178 | 178 | return $queryStr; |
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
182 | 182 | * Add an XML Document to the Solr Index |
183 | | - * |
| 183 | + * |
184 | 184 | * @param $xmlcontent - Solr XML Document |
185 | 185 | */ |
186 | | - public function solrAdd($xmlcontent) { |
| 186 | + public function solrAdd( $xmlcontent ) { |
187 | 187 | global $wgSolrUrl; |
188 | 188 | |
189 | 189 | $url = $wgSolrUrl . '/update?commit=true'; |
190 | | - $xmlcontent = str_replace('&', '+', $xmlcontent); |
191 | | - $xmlcontent = str_replace(' ', ' ', $xmlcontent); |
192 | | - $xmlcontent = str_replace(' ', ' ', $xmlcontent); |
193 | | - $xmlcontent = str_replace('&', ' ', $xmlcontent); |
194 | | - $xmlcontent = str_replace('&', ' ', $xmlcontent); |
| 190 | + $xmlcontent = str_replace( '&', '+', $xmlcontent ); |
| 191 | + $xmlcontent = str_replace( ' ', ' ', $xmlcontent ); |
| 192 | + $xmlcontent = str_replace( ' ', ' ', $xmlcontent ); |
| 193 | + $xmlcontent = str_replace( '&', ' ', $xmlcontent ); |
| 194 | + $xmlcontent = str_replace( '&', ' ', $xmlcontent ); |
195 | 195 | |
196 | | - return $this->solrSend($url, $xmlcontent); |
| 196 | + return $this->solrSend( $url, $xmlcontent ); |
197 | 197 | } |
198 | 198 | |
199 | 199 | /** |
200 | 200 | * Private Function for interactinig with Solr. |
201 | | - * |
| 201 | + * |
202 | 202 | * @param type $url |
203 | 203 | * @param type $xmlcontent |
204 | | - * @return SimpleXMLElement |
| 204 | + * @return SimpleXMLElement |
205 | 205 | */ |
206 | | - private function solrSend($url, $xmlcontent = false) { |
| 206 | + private function solrSend( $url, $xmlcontent = false ) { |
207 | 207 | $ch = curl_init(); |
208 | 208 | |
209 | | - $url = str_replace(' ', '+', $url); |
| 209 | + $url = str_replace( ' ', '+', $url ); |
210 | 210 | |
211 | | - curl_setopt($ch, CURLOPT_URL, $url); |
212 | | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
213 | | - curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
214 | | - curl_setopt($ch, CURLINFO_HEADER_OUT, 1); |
215 | | - |
216 | | - if ($xmlcontent) { |
217 | | - curl_setopt($ch, CURLOPT_POST, 1); |
218 | | - curl_setopt($ch, CURLOPT_HTTPHEADER, $this->header); |
219 | | - curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlcontent); |
| 211 | + curl_setopt( $ch, CURLOPT_URL, $url ); |
| 212 | + curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); |
| 213 | + curl_setopt( $ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1 ); |
| 214 | + curl_setopt( $ch, CURLINFO_HEADER_OUT, 1 ); |
| 215 | + |
| 216 | + if ( $xmlcontent ) { |
| 217 | + curl_setopt( $ch, CURLOPT_POST, 1 ); |
| 218 | + curl_setopt( $ch, CURLOPT_HTTPHEADER, $this->header ); |
| 219 | + curl_setopt( $ch, CURLOPT_POSTFIELDS, $xmlcontent ); |
220 | 220 | } |
221 | 221 | |
222 | | - $data = curl_exec($ch); |
223 | | - |
| 222 | + $data = curl_exec( $ch ); |
| 223 | + |
224 | 224 | if ( curl_errno( $ch ) != 0 ) { |
225 | 225 | throw new MWException( curl_error( $ch ) ); |
226 | 226 | } |
227 | | - |
228 | | - $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
229 | | - |
230 | | - curl_close($ch); |
231 | 227 | |
| 228 | + $httpCode = curl_getinfo( $ch, CURLINFO_HTTP_CODE ); |
| 229 | + |
| 230 | + curl_close( $ch ); |
| 231 | + |
232 | 232 | // if the request was successful |
233 | 233 | if ( $httpCode == 200 ) { |
234 | | - |
| 234 | + |
235 | 235 | try { |
236 | | - $xml = new SimpleXMLElement($data); |
237 | | - } catch (Exception $exc) { |
| 236 | + $xml = new SimpleXMLElement( $data ); |
| 237 | + } catch ( Exception $exc ) { |
238 | 238 | throw new MWException( $exc->getMessage() ); |
239 | 239 | } |
240 | | - |
| 240 | + |
241 | 241 | } else { // some error occurred |
242 | | - |
| 242 | + |
243 | 243 | // have to scrape the error message from the returned HTML |
244 | 244 | $xml = new DOMDocument; |
245 | 245 | $xml->loadHTML( $data ); |
246 | | - |
| 246 | + |
247 | 247 | $u = $xml->getElementsByTagName( 'u' ); |
248 | 248 | $errmsg = $xml->saveXML( $u->item( $u->length - 1 )->firstChild ); |
249 | 249 | |
— | — | @@ -252,41 +252,41 @@ |
253 | 253 | return $xml; |
254 | 254 | } |
255 | 255 | |
256 | | - //SOLR Functions |
| 256 | + // SOLR Functions |
257 | 257 | |
258 | 258 | /** |
259 | 259 | * Add a Document to the SolrIndex |
260 | | - * @param SolrDoc $file |
| 260 | + * @param SolrDoc $file |
261 | 261 | */ |
262 | | - public function addDoc(SolrDoc $file) { |
| 262 | + public function addDoc( SolrDoc $file ) { |
263 | 263 | $filekopf = "<add><doc>"; |
264 | 264 | $filefuss = "</doc></add>"; |
265 | 265 | $xmlcontent = $filekopf . $file->printFields() . $filefuss; |
266 | | - return $this->solrAdd($xmlcontent); |
| 266 | + return $this->solrAdd( $xmlcontent ); |
267 | 267 | } |
268 | 268 | |
269 | 269 | /** |
270 | 270 | * Remove a Document with the $id from the SolrIndex |
271 | | - * @param type $id |
| 271 | + * @param type $id |
272 | 272 | * @return type $xml - Response from Solr |
273 | 273 | */ |
274 | | - public function deleteDocId($id) { |
| 274 | + public function deleteDocId( $id ) { |
275 | 275 | $filekopf = "<delte><id>"; |
276 | 276 | $filefuss = "</id></delte>"; |
277 | 277 | $xmlcontent = $filekopf . $id . $filefuss; |
278 | | - return $this->solrAdd($xmlcontent); |
| 278 | + return $this->solrAdd( $xmlcontent ); |
279 | 279 | } |
280 | 280 | |
281 | 281 | /** |
282 | 282 | * Delete all Documents found by this Query |
283 | | - * @param type $query |
| 283 | + * @param type $query |
284 | 284 | * @return type $xml - Response from Solr |
285 | 285 | */ |
286 | | - public function deleteDocQuery($query) { |
| 286 | + public function deleteDocQuery( $query ) { |
287 | 287 | $filekopf = "<delte><query>"; |
288 | 288 | $filefuss = "</query></delte>"; |
289 | 289 | $xmlcontent = $filekopf . $query . $filefuss; |
290 | | - return $this->solrAdd($xmlcontent); |
| 290 | + return $this->solrAdd( $xmlcontent ); |
291 | 291 | } |
292 | 292 | |
293 | 293 | /** |
— | — | @@ -295,35 +295,35 @@ |
296 | 296 | */ |
297 | 297 | public function deleteAllDocs() { |
298 | 298 | $xmlcontent = '<delete><query>*:*</query></delete>'; |
299 | | - return $this->solrAdd($xmlcontent); |
| 299 | + return $this->solrAdd( $xmlcontent ); |
300 | 300 | } |
301 | 301 | |
302 | 302 | /** |
303 | 303 | * This Function is used for Storing an SMWSemanticData Item in the Solr Index |
304 | 304 | * |
305 | | - * @param SMWSemanticData $data |
| 305 | + * @param SMWSemanticData $data |
306 | 306 | */ |
307 | | - public function parseSemanticData(SMWSemanticData $data) { |
| 307 | + public function parseSemanticData( SMWSemanticData $data ) { |
308 | 308 | $solritem = new SolrDoc (); |
309 | 309 | |
310 | | - $solritem->addField("pagetitle", $data->getSubject()->getTitle()->getText()); |
311 | | - $solritem->addField("namespace", $data->getSubject()->getNamespace()); |
312 | | - $solritem->addField("dbkey", $data->getSubject()->getDBkey()); |
313 | | - $solritem->addField("interwiki", $data->getSubject()->getInterwiki()); |
314 | | - $solritem->addField("subobjectname", $data->getSubject()->getSubobjectName()); |
| 310 | + $solritem->addField( "pagetitle", $data->getSubject()->getTitle()->getText() ); |
| 311 | + $solritem->addField( "namespace", $data->getSubject()->getNamespace() ); |
| 312 | + $solritem->addField( "dbkey", $data->getSubject()->getDBkey() ); |
| 313 | + $solritem->addField( "interwiki", $data->getSubject()->getInterwiki() ); |
| 314 | + $solritem->addField( "subobjectname", $data->getSubject()->getSubobjectName() ); |
315 | 315 | |
316 | | - foreach ($data->getProperties() as $property) { |
317 | | - if (( $property->getKey() == '_SKEY' ) || ( $property->getKey() == '_REDI' )) { |
| 316 | + foreach ( $data->getProperties() as $property ) { |
| 317 | + if ( ( $property->getKey() == '_SKEY' ) || ( $property->getKey() == '_REDI' ) ) { |
318 | 318 | continue; // skip these here, we store them differently |
319 | 319 | } |
320 | 320 | |
321 | 321 | $propertyName = $property->getLabel(); |
322 | 322 | |
323 | | - foreach ($data->getPropertyValues($property) as $di) { |
324 | | - if ($di instanceof SMWDIError) { // error values, ignore |
| 323 | + foreach ( $data->getPropertyValues( $property ) as $di ) { |
| 324 | + if ( $di instanceof SMWDIError ) { // error values, ignore |
325 | 325 | continue; |
326 | 326 | } |
327 | | - switch ($di->getDIType()) { |
| 327 | + switch ( $di->getDIType() ) { |
328 | 328 | case 0: |
329 | 329 | // /// Data item ID that can be used to indicate that no data item class is appropriate |
330 | 330 | // const TYPE_NOTYPE = 0; |
— | — | @@ -332,58 +332,58 @@ |
333 | 333 | case 1: |
334 | 334 | // /// Data item ID for SMWDINumber |
335 | 335 | // const TYPE_NUMBER = 1; |
336 | | - $solritem->addField($propertyName . '_i', $di->getNumber()); |
337 | | - $solritem->addSortField($propertyName . '_i', $di->getNumber()); |
| 336 | + $solritem->addField( $propertyName . '_i', $di->getNumber() ); |
| 337 | + $solritem->addSortField( $propertyName . '_i', $di->getNumber() ); |
338 | 338 | break; |
339 | 339 | |
340 | 340 | case 2: |
341 | 341 | // /// Data item ID for SMWDIString |
342 | 342 | // const TYPE_STRING = 2; |
343 | | - $solritem->addField($propertyName . '_t', $di->getString()); |
344 | | - $solritem->addSortField($propertyName . '_t', $di->getString()); |
| 343 | + $solritem->addField( $propertyName . '_t', $di->getString() ); |
| 344 | + $solritem->addSortField( $propertyName . '_t', $di->getString() ); |
345 | 345 | break; |
346 | 346 | |
347 | 347 | case 3: |
348 | 348 | // /// Data item ID for SMWDIBlob |
349 | 349 | // const TYPE_BLOB = 3; |
350 | | - $solritem->addField($propertyName . '_t', $di->getString()); |
351 | | - $solritem->addSortField($propertyName . '_t', $di->getString()); |
| 350 | + $solritem->addField( $propertyName . '_t', $di->getString() ); |
| 351 | + $solritem->addSortField( $propertyName . '_t', $di->getString() ); |
352 | 352 | break; |
353 | 353 | |
354 | 354 | case 4: |
355 | 355 | // /// Data item ID for SMWDIBoolean |
356 | 356 | // const TYPE_BOOLEAN = 4; |
357 | | - $solritem->addField($propertyName . '_b', $di->getBoolean()); |
358 | | - $solritem->addSortField($propertyName . '_b', $di->getBoolean()); |
| 357 | + $solritem->addField( $propertyName . '_b', $di->getBoolean() ); |
| 358 | + $solritem->addSortField( $propertyName . '_b', $di->getBoolean() ); |
359 | 359 | break; |
360 | 360 | |
361 | 361 | case 5: |
362 | 362 | // /// Data item ID for SMWDIUri |
363 | 363 | // const TYPE_URI = 5; |
364 | | - $solritem->addField($propertyName . '_t', $di->getURI()); |
365 | | - $solritem->addSortField($propertyName . '_t', $di->getURI()); |
| 364 | + $solritem->addField( $propertyName . '_t', $di->getURI() ); |
| 365 | + $solritem->addSortField( $propertyName . '_t', $di->getURI() ); |
366 | 366 | break; |
367 | 367 | |
368 | 368 | case 6: |
369 | 369 | // /// Data item ID for SMWDITimePoint |
370 | 370 | // const TYPE_TIME = 6; |
371 | 371 | $date = $di->getYear() . '-' . $di->getMonth() . '-' . $di->getDay() . 'T' . $di->getHour() . ':' . $di->getMinute() . ':' . $di->getSecond() . 'Z'; |
372 | | - $solritem->addField($propertyName . '_dt', $date); |
373 | | - $solritem->addSortField($propertyName . '_dt', $date); |
| 372 | + $solritem->addField( $propertyName . '_dt', $date ); |
| 373 | + $solritem->addSortField( $propertyName . '_dt', $date ); |
374 | 374 | break; |
375 | 375 | |
376 | 376 | case 7: |
377 | 377 | // /// Data item ID for SMWDIGeoCoord |
378 | 378 | // const TYPE_GEO = 7; |
379 | | - //TODO: Implement range Search in SOLR |
380 | | - $solritem->addField($propertyName . '_lat', $di->getLatitude()); |
381 | | - $solritem->addField($propertyName . '_lng', $di->getLongitude()); |
| 379 | + // TODO: Implement range Search in SOLR |
| 380 | + $solritem->addField( $propertyName . '_lat', $di->getLatitude() ); |
| 381 | + $solritem->addField( $propertyName . '_lng', $di->getLongitude() ); |
382 | 382 | break; |
383 | 383 | |
384 | 384 | case 8: |
385 | 385 | // /// Data item ID for SMWDIContainer |
386 | 386 | // const TYPE_CONTAINER = 8 |
387 | | - //TODO: What the Hell is this used for ??? |
| 387 | + // TODO: What the Hell is this used for ??? |
388 | 388 | $data->getSubject()->getTitle()->getText() . " : "; |
389 | 389 | break; |
390 | 390 | |
— | — | @@ -391,12 +391,12 @@ |
392 | 392 | // /// Data item ID for SMWDIWikiPage |
393 | 393 | // const TYPE_WIKIPAGE = 9; |
394 | 394 | $ns = $di->getNamespace(); |
395 | | - if ($ns == 0) { |
396 | | - $solritem->addField($propertyName . '_s', $di->getTitle()); |
397 | | - } elseif ($ns == 14) { |
| 395 | + if ( $ns == 0 ) { |
| 396 | + $solritem->addField( $propertyName . '_s', $di->getTitle() ); |
| 397 | + } elseif ( $ns == 14 ) { |
398 | 398 | $title = $di->getTitle(); |
399 | | - $solritem->addField('category', substr($title, stripos($title, ':') + 1)); |
400 | | - } |
| 399 | + $solritem->addField( 'category', substr( $title, stripos( $title, ':' ) + 1 ) ); |
| 400 | + } |
401 | 401 | break; |
402 | 402 | |
403 | 403 | case 10: |
— | — | @@ -421,7 +421,7 @@ |
422 | 422 | } |
423 | 423 | } |
424 | 424 | } |
425 | | - $this->addDoc($solritem); |
| 425 | + $this->addDoc( $solritem ); |
426 | 426 | } |
427 | 427 | |
428 | 428 | } |
Index: trunk/extensions/SolrStore/SolrStore.alias.php |
— | — | @@ -6,9 +6,8 @@ |
7 | 7 | * @file |
8 | 8 | * @author Simon Bachenberg |
9 | 9 | */ |
10 | | - |
11 | 10 | $specialPageAliases = array(); |
12 | 11 | |
13 | | -$specialPageAliases['en'] = array('solrsearch' => array('SolrSearch', 'SpecialSolrSearch')); |
14 | | -$specialPageAliases['de'] = array('solrsearch' => array('SolrSearch', 'SpecialSolrSearch')); |
| 12 | +$specialPageAliases['en'] = array( 'solrsearch' => array( 'SolrSearch', 'SpecialSolrSearch' ) ); |
| 13 | +$specialPageAliases['de'] = array( 'solrsearch' => array( 'SolrSearch', 'SpecialSolrSearch' ) ); |
15 | 14 | |
Index: trunk/extensions/SolrStore/SolrDoc.php |
— | — | @@ -16,50 +16,50 @@ |
17 | 17 | private $output; |
18 | 18 | private $min = array (); |
19 | 19 | private $max = array (); |
20 | | - |
| 20 | + |
21 | 21 | /** |
22 | 22 | * Add a Field to the SolrDoc |
23 | | - * |
| 23 | + * |
24 | 24 | * @param type $name of the Field |
25 | 25 | * @param type $value of the Field |
26 | 26 | */ |
27 | | - public function addField($name,$value){ |
28 | | - $this->output.= '<field name="' . $name . '">' . $value . '</field>' ; |
| 27 | + public function addField( $name, $value ) { |
| 28 | + $this->output .= '<field name="' . $name . '">' . $value . '</field>' ; |
29 | 29 | } |
30 | | - |
| 30 | + |
31 | 31 | /** |
32 | 32 | * This Function gets a Multivalued Field and splits it into a max and a min value for Sorting |
33 | | - * |
| 33 | + * |
34 | 34 | * @param type $name of the Field |
35 | 35 | * @param type $value of the Field |
36 | 36 | */ |
37 | | - public function addSortField($name, $value) { |
38 | | - //Does a min/max Field with this name exist ? |
39 | | - if (isset ($this->min[$name]) && isset ($this->max[$name])){ |
40 | | - if (strcasecmp($this->min[$name], $value) > 0){ |
41 | | - //If the new String is Less the Old one replace them |
| 37 | + public function addSortField( $name, $value ) { |
| 38 | + // Does a min/max Field with this name exist ? |
| 39 | + if ( isset ( $this->min[$name] ) && isset ( $this->max[$name] ) ) { |
| 40 | + if ( strcasecmp( $this->min[$name], $value ) > 0 ) { |
| 41 | + // If the new String is Less the Old one replace them |
42 | 42 | $this->min[$name] = $value; |
43 | 43 | } |
44 | | - if(strcasecmp($this->max[$name], $value) < 0){ |
45 | | - //If the new String is Bigger than Old one replace them |
| 44 | + if ( strcasecmp( $this->max[$name], $value ) < 0 ) { |
| 45 | + // If the new String is Bigger than Old one replace them |
46 | 46 | $this->max[$name] = $value; |
47 | 47 | } |
48 | | - }else{ |
| 48 | + } else { |
49 | 49 | $this->min[$name] = $value; |
50 | 50 | $this->max[$name] = $value; |
51 | 51 | } |
52 | 52 | } |
53 | | - |
| 53 | + |
54 | 54 | public function printFields() { |
55 | 55 | $all = $this->output; |
56 | | - |
57 | | - foreach ($this->min as $name => $value) { |
| 56 | + |
| 57 | + foreach ( $this->min as $name => $value ) { |
58 | 58 | $all .= '<field name="' . $name . 'min">' . $value . '</field>' ; |
59 | 59 | } |
60 | | - foreach ($this->max as $name => $value) { |
| 60 | + foreach ( $this->max as $name => $value ) { |
61 | 61 | $all .= '<field name="' . $name . 'max">' . $value . '</field>' ; |
62 | 62 | } |
63 | | - |
| 63 | + |
64 | 64 | return $all; |
65 | 65 | } |
66 | 66 | } |
Index: trunk/extensions/SolrStore/SolrSearch.php |
— | — | @@ -9,7 +9,7 @@ |
10 | 10 | |
11 | 11 | /** |
12 | 12 | * TODO: Insert class description |
13 | | - * |
| 13 | + * |
14 | 14 | * @ingroup SolrStore |
15 | 15 | */ |
16 | 16 | class SolrSearch extends SearchEngine { |
— | — | @@ -18,11 +18,11 @@ |
19 | 19 | var $offset = 0; |
20 | 20 | var $prefix = ''; |
21 | 21 | var $searchTerms = array(); |
22 | | - var $namespaces = array(NS_MAIN); |
| 22 | + var $namespaces = array( NS_MAIN ); |
23 | 23 | var $showRedirects = false; |
24 | 24 | var $solrTalker; |
25 | 25 | |
26 | | - function __construct($db = null) { |
| 26 | + function __construct( $db = null ) { |
27 | 27 | global $wgSolrTalker; |
28 | 28 | } |
29 | 29 | |
— | — | @@ -34,8 +34,8 @@ |
35 | 35 | * @return SolrSearchSet |
36 | 36 | * @access public |
37 | 37 | */ |
38 | | - function searchText($term) { |
39 | | - return SolrSearchSet::newFromQuery(isset($this->related) ? 'related' : 'search', $term, $this->namespaces, $this->limit, $this->offset, $this->searchingEverything()); |
| 38 | + function searchText( $term ) { |
| 39 | + return SolrSearchSet::newFromQuery( isset( $this->related ) ? 'related' : 'search', $term, $this->namespaces, $this->limit, $this->offset, $this->searchingEverything() ); |
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
— | — | @@ -45,19 +45,19 @@ |
46 | 46 | * @return SolrSearchSet |
47 | 47 | * @access public |
48 | 48 | */ |
49 | | - function searchTitle($term) { |
| 49 | + function searchTitle( $term ) { |
50 | 50 | return null; |
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
54 | 54 | * PrefixSearchBackend override for OpenSearch results |
55 | 55 | */ |
56 | | - static function prefixSearch($ns, $search, $limit, &$results) { |
| 56 | + static function prefixSearch( $ns, $search, $limit, &$results ) { |
57 | 57 | echo "Prefix Search!<br/>"; |
58 | | - $it = SolrSearchSet::newFromQuery('prefix', $search, $ns, $limit, 0); |
| 58 | + $it = SolrSearchSet::newFromQuery( 'prefix', $search, $ns, $limit, 0 ); |
59 | 59 | $results = array(); |
60 | | - if ($it) { // $it can be null |
61 | | - while ($res = $it->next()) { |
| 60 | + if ( $it ) { // $it can be null |
| 61 | + while ( $res = $it->next() ) { |
62 | 62 | $results[] = $res->getTitle()->getPrefixedText(); |
63 | 63 | } |
64 | 64 | } |
— | — | @@ -66,30 +66,30 @@ |
67 | 67 | |
68 | 68 | /** |
69 | 69 | * Check if we are searching all the namespaces on this wiki |
70 | | - * |
| 70 | + * |
71 | 71 | * @return boolean |
72 | 72 | */ |
73 | 73 | function searchingEverything() { |
74 | | - return $this->namespaces == array_keys(SearchEngine::searchableNamespaces()); |
| 74 | + return $this->namespaces == array_keys( SearchEngine::searchableNamespaces() ); |
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
78 | 78 | * Prepare query for the Solr-search daemon: |
79 | | - * |
80 | | - * 1) rewrite namespaces into standardized form |
| 79 | + * |
| 80 | + * 1) rewrite namespaces into standardized form |
81 | 81 | * e.g. image:clouds -> [6]:clouds |
82 | | - * |
| 82 | + * |
83 | 83 | * 2) rewrite localizations of "search everything" keyword |
84 | 84 | * e.g. alle:heidegger -> all:heidegger |
85 | 85 | * |
86 | | - * @param string query |
| 86 | + * @param string query |
87 | 87 | * @return string rewritten query |
88 | 88 | * @access private |
89 | 89 | */ |
90 | | - function replacePrefixes($query) { |
| 90 | + function replacePrefixes( $query ) { |
91 | 91 | global $wgContLang, $wgSolrUseRelated; |
92 | 92 | $fname = 'SolrSearch::replacePrefixes'; |
93 | | - wfProfileIn($fname); |
| 93 | + wfProfileIn( $fname ); |
94 | 94 | $start = 0; |
95 | 95 | $len = 0; // token start pos and length |
96 | 96 | $rewritten = ''; // rewritten query |
— | — | @@ -97,65 +97,65 @@ |
98 | 98 | $inquotes = false; |
99 | 99 | |
100 | 100 | // "search everything" keyword |
101 | | - $allkeyword = wfMsgForContent('searchall'); |
| 101 | + $allkeyword = wfMsgForContent( 'searchall' ); |
102 | 102 | |
103 | | - $qlen = strlen($query); |
| 103 | + $qlen = strlen( $query ); |
104 | 104 | |
105 | 105 | // quick check, most of the time we don't need any rewriting |
106 | | - if (strpos($query, ':') === false) { |
107 | | - wfProfileOut($fname); |
| 106 | + if ( strpos( $query, ':' ) === false ) { |
| 107 | + wfProfileOut( $fname ); |
108 | 108 | return $query; |
109 | 109 | } |
110 | 110 | |
111 | 111 | // check if this is query for related articles |
112 | | - $relatedkey = wfMsgForContent('searchrelated') . ':'; |
113 | | - if ($wgSolrUseRelated && strncmp($query, $relatedkey, strlen($relatedkey)) == 0) { |
| 112 | + $relatedkey = wfMsgForContent( 'searchrelated' ) . ':'; |
| 113 | + if ( $wgSolrUseRelated && strncmp( $query, $relatedkey, strlen( $relatedkey ) ) == 0 ) { |
114 | 114 | $this->related = true; |
115 | | - list($dummy, $ret) = explode(":", $query, 2); |
116 | | - wfProfileOut($fname); |
117 | | - return trim($ret); |
| 115 | + list( $dummy, $ret ) = explode( ":", $query, 2 ); |
| 116 | + wfProfileOut( $fname ); |
| 117 | + return trim( $ret ); |
118 | 118 | } |
119 | 119 | |
120 | 120 | global $wgCanonicalNamespaceNames, $wgNamespaceAliases; |
121 | | - $nsNamesRaw = array_merge($wgContLang->getNamespaces(), $wgCanonicalNamespaceNames, array_keys(array_merge($wgNamespaceAliases, $wgContLang->getNamespaceAliases()))); |
| 121 | + $nsNamesRaw = array_merge( $wgContLang->getNamespaces(), $wgCanonicalNamespaceNames, array_keys( array_merge( $wgNamespaceAliases, $wgContLang->getNamespaceAliases() ) ) ); |
122 | 122 | |
123 | 123 | # add all namespace names w/o spaces |
124 | 124 | $nsNames = array(); |
125 | | - foreach ($nsNamesRaw as $ns) { |
126 | | - if ($ns != '') { |
| 125 | + foreach ( $nsNamesRaw as $ns ) { |
| 126 | + if ( $ns != '' ) { |
127 | 127 | $nsNames[] = $ns; |
128 | | - $nsNames[] = str_replace('_', ' ', $ns); |
| 128 | + $nsNames[] = str_replace( '_', ' ', $ns ); |
129 | 129 | } |
130 | 130 | } |
131 | 131 | |
132 | | - $regexp = implode('|', array_unique($nsNames)); |
| 132 | + $regexp = implode( '|', array_unique( $nsNames ) ); |
133 | 133 | |
134 | 134 | # rewrite the query by replacing valid namespace names |
135 | | - $parts = preg_split('/(")/', $query, -1, PREG_SPLIT_DELIM_CAPTURE); |
| 135 | + $parts = preg_split( '/(")/', $query, -1, PREG_SPLIT_DELIM_CAPTURE ); |
136 | 136 | $inquotes = false; |
137 | 137 | $rewritten = ''; |
138 | | - foreach ($parts as $part) { |
139 | | - if ($part == '"') { # stuff in quote doesnt get rewritten |
| 138 | + foreach ( $parts as $part ) { |
| 139 | + if ( $part == '"' ) { # stuff in quote doesnt get rewritten |
140 | 140 | $rewritten .= $part; |
141 | 141 | $inquotes = !$inquotes; |
142 | | - } elseif ($inquotes) { |
| 142 | + } elseif ( $inquotes ) { |
143 | 143 | $rewritten .= $part; |
144 | 144 | } else { |
145 | 145 | # replace namespaces |
146 | | - $r = preg_replace_callback('/(^|[| :])(' . $regexp . '):/i', array($this, 'replaceNamespace'), $part); |
| 146 | + $r = preg_replace_callback( '/(^|[| :])(' . $regexp . '):/i', array( $this, 'replaceNamespace' ), $part ); |
147 | 147 | # replace to backend all: notation |
148 | | - $rewritten .= str_replace($allkeyword . ':', 'all:', $r); |
| 148 | + $rewritten .= str_replace( $allkeyword . ':', 'all:', $r ); |
149 | 149 | } |
150 | 150 | } |
151 | | - wfProfileOut($fname); |
| 151 | + wfProfileOut( $fname ); |
152 | 152 | return $rewritten; |
153 | 153 | } |
154 | 154 | |
155 | 155 | /** callback to replace namespace names to internal notation, e.g. User: -> [2]: */ |
156 | | - function replaceNamespace($matches) { |
| 156 | + function replaceNamespace( $matches ) { |
157 | 157 | global $wgContLang; |
158 | | - $inx = $wgContLang->getNsIndex(str_replace(' ', '_', $matches[2])); |
159 | | - if ($inx === false) |
| 158 | + $inx = $wgContLang->getNsIndex( str_replace( ' ', '_', $matches[2] ) ); |
| 159 | + if ( $inx === false ) |
160 | 160 | return $matches[0]; |
161 | 161 | else |
162 | 162 | return $matches[1] . "[$inx]:"; |
— | — | @@ -166,11 +166,11 @@ |
167 | 167 | } |
168 | 168 | |
169 | 169 | /** Merge the prefix into the query (if any) */ |
170 | | - function transformSearchTerm($term) { |
| 170 | + function transformSearchTerm( $term ) { |
171 | 171 | global $wgSolrSearchVersion; |
172 | 172 | |
173 | | - if ($wgSolrSearchVersion >= 2.1 && $this->prefix != '') { |
174 | | -# convert to internal backend prefix notation |
| 173 | + if ( $wgSolrSearchVersion >= 2.1 && $this->prefix != '' ) { |
| 174 | +# convert to internal backend prefix notation |
175 | 175 | $term = $term . ' prefix:' . $this->prefix; |
176 | 176 | } |
177 | 177 | return $term; |
— | — | @@ -182,7 +182,7 @@ |
183 | 183 | |
184 | 184 | /** |
185 | 185 | * Construct a result object from single result line |
186 | | - * |
| 186 | + * |
187 | 187 | * @param array $lines |
188 | 188 | * @param string $method - method used to fetch these results |
189 | 189 | * @return array (float, Title) |
— | — | @@ -192,7 +192,7 @@ |
193 | 193 | return false; |
194 | 194 | } |
195 | 195 | |
196 | | - function SolrResult($result, $method) { |
| 196 | + function SolrResult( $result, $method ) { |
197 | 197 | global $wgContLang; |
198 | 198 | |
199 | 199 | $score = null; |
— | — | @@ -201,7 +201,7 @@ |
202 | 202 | $title = null; |
203 | 203 | |
204 | 204 | $xml = $result; |
205 | | - wfDebug("Solr line: '$result'\n"); |
| 205 | + wfDebug( "Solr line: '$result'\n" ); |
206 | 206 | |
207 | 207 | // Defining Results |
208 | 208 | |
— | — | @@ -210,29 +210,29 @@ |
211 | 211 | $this->mScore = $score; |
212 | 212 | |
213 | 213 | |
214 | | - //------------------------------------- |
| 214 | + // ------------------------------------- |
215 | 215 | // Get The Shit out of da XML |
216 | | - //------------------------------------- |
217 | | - foreach ($xml->arr as $doc) { |
218 | | - switch ($doc['name']) { |
| 216 | + // ------------------------------------- |
| 217 | + foreach ( $xml->arr as $doc ) { |
| 218 | + switch ( $doc['name'] ) { |
219 | 219 | case 'text': |
220 | 220 | $nsText = $doc->str; |
221 | 221 | |
222 | 222 | $this->mSize = ""; |
223 | | - $this->mWordCount = count($doc->str); |
| 223 | + $this->mWordCount = count( $doc->str ); |
224 | 224 | $snipmax = 10; |
225 | 225 | $textsnip = ""; |
226 | 226 | $textsnipvar = 0; |
227 | | - foreach ($doc->str as $inner) { |
| 227 | + foreach ( $doc->str as $inner ) { |
228 | 228 | $textsnipvar++; |
229 | | - if ($textsnipvar >= 4 && $textsnipvar <= $snipmax) { |
230 | | - $textsnip.=" " . $inner; |
| 229 | + if ( $textsnipvar >= 4 && $textsnipvar <= $snipmax ) { |
| 230 | + $textsnip .= " " . $inner; |
231 | 231 | } |
232 | | - $this->mSize = $this->mSize + strlen($inner); |
| 232 | + $this->mSize = $this->mSize + strlen( $inner ); |
233 | 233 | } |
234 | | - $textsnip.="..."; |
235 | | - $this->mSize = ($this->mSize / 3); |
236 | | - //$this->mSize=$size; |
| 234 | + $textsnip .= "..."; |
| 235 | + $this->mSize = ( $this->mSize / 3 ); |
| 236 | + // $this->mSize=$size; |
237 | 237 | break; |
238 | 238 | case 'Zuletzt geändert_dt': |
239 | 239 | $this->mDate = $doc->date; |
— | — | @@ -240,8 +240,8 @@ |
241 | 241 | } |
242 | 242 | } |
243 | 243 | |
244 | | - foreach ($xml->str as $docs) { |
245 | | - switch ($docs['name']) { |
| 244 | + foreach ( $xml->str as $docs ) { |
| 245 | + switch ( $docs['name'] ) { |
246 | 246 | case 'pagetitle': |
247 | 247 | $this->mTitle = $doc->str; |
248 | 248 | break; |
— | — | @@ -253,47 +253,47 @@ |
254 | 254 | break; |
255 | 255 | } |
256 | 256 | } |
257 | | - foreach ($xml->int as $doci) { |
258 | | - switch ($doci['name']) { |
| 257 | + foreach ( $xml->int as $doci ) { |
| 258 | + switch ( $doci['name'] ) { |
259 | 259 | case 'namespace': |
260 | 260 | $namespace = $doc->str; |
261 | 261 | break; |
262 | 262 | } |
263 | 263 | } |
264 | 264 | |
265 | | - $title = urldecode($title); |
266 | | - if (!isset($nsText)) |
267 | | - $nsText = $wgContLang->getNsText($namespace); |
| 265 | + $title = urldecode( $title ); |
| 266 | + if ( !isset( $nsText ) ) |
| 267 | + $nsText = $wgContLang->getNsText( $namespace ); |
268 | 268 | else |
269 | | - $nsText = urldecode($nsText); |
| 269 | + $nsText = urldecode( $nsText ); |
270 | 270 | |
271 | 271 | // make title |
272 | | - $this->mTitle = Title::makeTitle($namespace, $title); |
| 272 | + $this->mTitle = Title::makeTitle( $namespace, $title ); |
273 | 273 | |
274 | 274 | // HIGHLIHT |
275 | 275 | // <em> & </em> Fix to <b> // if not, no highlighting !! |
276 | 276 | // TITLE (LINK) |
277 | | - if ($xml->highlight->title != '') { |
278 | | - $this->mHighlightTitle = str_replace("<em>", "<b>", $xml->highlight->title); |
279 | | - $this->mHighlightTitle = str_replace("</em>", "</b>", $this->mHighlightTitle); |
| 277 | + if ( $xml->highlight->title != '' ) { |
| 278 | + $this->mHighlightTitle = str_replace( "<em>", "<b>", $xml->highlight->title ); |
| 279 | + $this->mHighlightTitle = str_replace( "</em>", "</b>", $this->mHighlightTitle ); |
280 | 280 | } else { |
281 | 281 | $this->mHighlightTitle = ''; |
282 | 282 | } |
283 | 283 | // TEXT (under Link) |
284 | | - //$this->mHighlightText=$xml->highlight->title; |
285 | | - if ($xml->highlight->Inhalt != '') { |
286 | | - $this->mHighlightText = str_replace("<em>", "<b>", $xml->highlight->Inhalt); |
287 | | - $this->mHighlightText = str_replace("</em>", "</b>", $this->mHighlightText); |
288 | | - $this->mHighlightText.="..."; |
289 | | - } else {//$this->mHighlightText=textsnip; |
290 | | - if (isset($_REQUEST['search']) != '' && isset($textsnip) != '') { |
291 | | - if (strpos(strtolower($textsnip), strtolower($_REQUEST['search']))) { |
292 | | - $tempc = strlen($_REQUEST['search']); |
293 | | - $pos1 = strpos(strtolower($textsnip), strtolower($_REQUEST['search'])); |
294 | | - $tmpa = substr($textsnip, 0, $pos1); |
295 | | - $tmpb = substr($textsnip, ($pos1 + $tempc)); |
296 | | - $this->mHighlightText = $tmpa . "<b>" . substr($textsnip, $pos1, $tempc) . "</b>" . $tmpb; |
297 | | - //str_replace($_REQUEST['search'],"<b>".$_REQUEST['search']."</b>",$textsnip); |
| 284 | + // $this->mHighlightText=$xml->highlight->title; |
| 285 | + if ( $xml->highlight->Inhalt != '' ) { |
| 286 | + $this->mHighlightText = str_replace( "<em>", "<b>", $xml->highlight->Inhalt ); |
| 287 | + $this->mHighlightText = str_replace( "</em>", "</b>", $this->mHighlightText ); |
| 288 | + $this->mHighlightText .= "..."; |
| 289 | + } else {// $this->mHighlightText=textsnip; |
| 290 | + if ( isset( $_REQUEST['search'] ) != '' && isset( $textsnip ) != '' ) { |
| 291 | + if ( strpos( strtolower( $textsnip ), strtolower( $_REQUEST['search'] ) ) ) { |
| 292 | + $tempc = strlen( $_REQUEST['search'] ); |
| 293 | + $pos1 = strpos( strtolower( $textsnip ), strtolower( $_REQUEST['search'] ) ); |
| 294 | + $tmpa = substr( $textsnip, 0, $pos1 ); |
| 295 | + $tmpb = substr( $textsnip, ( $pos1 + $tempc ) ); |
| 296 | + $this->mHighlightText = $tmpa . "<b>" . substr( $textsnip, $pos1, $tempc ) . "</b>" . $tmpb; |
| 297 | + // str_replace($_REQUEST['search'],"<b>".$_REQUEST['search']."</b>",$textsnip); |
298 | 298 | } else { |
299 | 299 | $this->mHighlightText = $textsnip; |
300 | 300 | } |
— | — | @@ -315,19 +315,19 @@ |
316 | 316 | * @param boolean $useFinalSeparator |
317 | 317 | * @return array (highlighted, unmodified text) |
318 | 318 | */ |
319 | | - function extractSnippet($lines, $nsText, $type, $useFinalSeparator=false) { |
320 | | - if (!array_key_exists($type, $lines)) |
321 | | - return array(null, null); |
| 319 | + function extractSnippet( $lines, $nsText, $type, $useFinalSeparator = false ) { |
| 320 | + if ( !array_key_exists( $type, $lines ) ) |
| 321 | + return array( null, null ); |
322 | 322 | $ret = ""; |
323 | 323 | $original = null; |
324 | | - foreach ($lines[$type] as $h) { |
325 | | - list($s, $o) = $this->extractSnippetLine($h, $useFinalSeparator); |
| 324 | + foreach ( $lines[$type] as $h ) { |
| 325 | + list( $s, $o ) = $this->extractSnippetLine( $h, $useFinalSeparator ); |
326 | 326 | $ret .= $s; |
327 | 327 | $original = $o; |
328 | 328 | } |
329 | | - if ($nsText != '') |
| 329 | + if ( $nsText != '' ) |
330 | 330 | $ret = $nsText . ':' . $ret; |
331 | | - return array($ret, $original); |
| 331 | + return array( $ret, $original ); |
332 | 332 | } |
333 | 333 | |
334 | 334 | /** |
— | — | @@ -338,67 +338,67 @@ |
339 | 339 | * @access protected |
340 | 340 | * @return array(snippet,unmodified text) |
341 | 341 | */ |
342 | | - function extractSnippetLine($line, $useFinalSeparator) { |
343 | | - $parts = explode(" ", $line); |
344 | | - if (count($parts) != 4 && count($parts) != 5) { |
345 | | - wfDebug("Bad result line:" . $line . "\n"); |
| 342 | + function extractSnippetLine( $line, $useFinalSeparator ) { |
| 343 | + $parts = explode( " ", $line ); |
| 344 | + if ( count( $parts ) != 4 && count( $parts ) != 5 ) { |
| 345 | + wfDebug( "Bad result line:" . $line . "\n" ); |
346 | 346 | return ""; |
347 | 347 | } |
348 | | - $splits = $this->stripBracketsSplit($parts[0]); |
349 | | - $highlight = $this->stripBracketsSplit($parts[1]); |
350 | | - $suffix = urldecode($this->stripBrackets($parts[2])); |
351 | | - $text = urldecode($parts[3]); |
| 348 | + $splits = $this->stripBracketsSplit( $parts[0] ); |
| 349 | + $highlight = $this->stripBracketsSplit( $parts[1] ); |
| 350 | + $suffix = urldecode( $this->stripBrackets( $parts[2] ) ); |
| 351 | + $text = urldecode( $parts[3] ); |
352 | 352 | $original = null; |
353 | | - if (count($parts) > 4) |
354 | | - $original = urldecode($parts[4]); |
| 353 | + if ( count( $parts ) > 4 ) |
| 354 | + $original = urldecode( $parts[4] ); |
355 | 355 | |
356 | | - $splits[] = strlen($text); |
| 356 | + $splits[] = strlen( $text ); |
357 | 357 | $start = 0; |
358 | 358 | $snippet = ""; |
359 | 359 | $hi = 0; |
360 | | - $ellipsis = wfMsgForContent('ellipsis'); |
| 360 | + $ellipsis = wfMsgForContent( 'ellipsis' ); |
361 | 361 | |
362 | | - foreach ($splits as $sp) { |
363 | | - $sp = intval($sp); |
| 362 | + foreach ( $splits as $sp ) { |
| 363 | + $sp = intval( $sp ); |
364 | 364 | // highlight words! |
365 | | - while ($hi < count($highlight) && intval($highlight[$hi]) < $sp) { |
366 | | - $s = intval($highlight[$hi]); |
367 | | - $e = intval($highlight[$hi + 1]); |
368 | | - $snippet .= substr($text, $start, $s - $start) . "<span class='searchmatch'>" . substr($text, $s, $e - $s) . "</span>"; |
| 365 | + while ( $hi < count( $highlight ) && intval( $highlight[$hi] ) < $sp ) { |
| 366 | + $s = intval( $highlight[$hi] ); |
| 367 | + $e = intval( $highlight[$hi + 1] ); |
| 368 | + $snippet .= substr( $text, $start, $s - $start ) . "<span class='searchmatch'>" . substr( $text, $s, $e - $s ) . "</span>"; |
369 | 369 | $start = $e; |
370 | 370 | $hi += 2; |
371 | 371 | } |
372 | 372 | // copy till split point |
373 | | - $snippet .= substr($text, $start, $sp - $start); |
374 | | - if ($sp == strlen($text) && $suffix != '') |
| 373 | + $snippet .= substr( $text, $start, $sp - $start ); |
| 374 | + if ( $sp == strlen( $text ) && $suffix != '' ) |
375 | 375 | $snippet .= $suffix; |
376 | | - else if ($useFinalSeparator) |
| 376 | + else if ( $useFinalSeparator ) |
377 | 377 | $snippet .= " <b>" . $ellipsis . "</b> "; |
378 | 378 | |
379 | 379 | $start = $sp; |
380 | 380 | } |
381 | | - return array($snippet, $original); |
| 381 | + return array( $snippet, $original ); |
382 | 382 | } |
383 | 383 | |
384 | 384 | /** |
385 | 385 | * @access private |
386 | 386 | */ |
387 | | - function stripBrackets($str) { |
388 | | - if ($str == '[]') |
| 387 | + function stripBrackets( $str ) { |
| 388 | + if ( $str == '[]' ) |
389 | 389 | return ''; |
390 | | - return substr($str, 1, strlen($str) - 2); |
| 390 | + return substr( $str, 1, strlen( $str ) - 2 ); |
391 | 391 | } |
392 | 392 | |
393 | 393 | /** |
394 | 394 | * @access private |
395 | 395 | * @return array |
396 | 396 | */ |
397 | | - function stripBracketsSplit($str) { |
398 | | - $strip = $this->stripBrackets($str); |
399 | | - if ($strip == '') |
| 397 | + function stripBracketsSplit( $str ) { |
| 398 | + $strip = $this->stripBrackets( $str ); |
| 399 | + if ( $strip == '' ) |
400 | 400 | return array(); |
401 | 401 | else |
402 | | - return explode(",", $strip); |
| 402 | + return explode( ",", $strip ); |
403 | 403 | } |
404 | 404 | |
405 | 405 | function getTitle() { |
— | — | @@ -406,27 +406,27 @@ |
407 | 407 | } |
408 | 408 | |
409 | 409 | function getScore() { |
410 | | - if (is_null($this->mScore)) |
411 | | - return null; // Solr scores are meaningless to the user... |
412 | | - |
| 410 | + if ( is_null( $this->mScore ) ) |
| 411 | + return null; // Solr scores are meaningless to the user... |
| 412 | + |
413 | 413 | // echo($this->mScore." "); |
414 | | - return floatval($this->mScore); |
| 414 | + return floatval( $this->mScore ); |
415 | 415 | } |
416 | 416 | |
417 | | - function getTitleSnippet($terms) { |
418 | | - if (is_null($this->mHighlightTitle)) |
| 417 | + function getTitleSnippet( $terms ) { |
| 418 | + if ( is_null( $this->mHighlightTitle ) ) |
419 | 419 | return ''; |
420 | 420 | return $this->mHighlightTitle; |
421 | 421 | } |
422 | 422 | |
423 | | - function getTextSnippet($terms) { |
424 | | - if (is_null($this->mHighlightText)) |
425 | | - return parent::getTextSnippet($terms); |
| 423 | + function getTextSnippet( $terms ) { |
| 424 | + if ( is_null( $this->mHighlightText ) ) |
| 425 | + return parent::getTextSnippet( $terms ); |
426 | 426 | return $this->mHighlightText; |
427 | 427 | } |
428 | 428 | |
429 | | - function getRedirectSnippet($terms) { |
430 | | - /* if (isset($this->mHighlightRedirect)) |
| 429 | + function getRedirectSnippet( $terms ) { |
| 430 | + /* if (isset($this->mHighlightRedirect)) |
431 | 431 | if (is_null($this->mHighlightRedirect)) |
432 | 432 | return ''; |
433 | 433 | return $this->mHighlightRedirect; |
— | — | @@ -439,13 +439,13 @@ |
440 | 440 | } |
441 | 441 | |
442 | 442 | function getSectionSnippet() { |
443 | | - if (is_null($this->mHighlightSection)) |
| 443 | + if ( is_null( $this->mHighlightSection ) ) |
444 | 444 | return null; |
445 | 445 | return $this->mHighlightSection; |
446 | 446 | } |
447 | 447 | |
448 | 448 | function getSectionTitle() { |
449 | | - if (is_null($this->mSectionTitle)) |
| 449 | + if ( is_null( $this->mSectionTitle ) ) |
450 | 450 | return null; |
451 | 451 | return $this->mSectionTitle; |
452 | 452 | } |
— | — | @@ -459,19 +459,19 @@ |
460 | 460 | } |
461 | 461 | |
462 | 462 | function getTimestamp() { |
463 | | - if (is_null($this->mDate)) |
| 463 | + if ( is_null( $this->mDate ) ) |
464 | 464 | return parent::getTimestamp(); |
465 | 465 | return $this->mDate; |
466 | 466 | } |
467 | 467 | |
468 | 468 | function getWordCount() { |
469 | | - if (is_null($this->mWordCount)) |
| 469 | + if ( is_null( $this->mWordCount ) ) |
470 | 470 | return parent::getWordCount(); |
471 | 471 | return $this->mWordCount; |
472 | 472 | } |
473 | 473 | |
474 | 474 | function getByteSize() { |
475 | | - if (is_null($this->mSize)) |
| 475 | + if ( is_null( $this->mSize ) ) |
476 | 476 | return parent::getByteSize(); |
477 | 477 | return $this->mSize; |
478 | 478 | } |
— | — | @@ -497,30 +497,30 @@ |
498 | 498 | * @return array |
499 | 499 | * @access public |
500 | 500 | */ |
501 | | - static function newFromQuery($method, $query, $namespaces = array(), $limit = 20, $offset = 0, $searchAll = False) { |
| 501 | + static function newFromQuery( $method, $query, $namespaces = array(), $limit = 20, $offset = 0, $searchAll = False ) { |
502 | 502 | $fname = 'SolrSearchSet::newFromQuery'; |
503 | | - wfProfileIn($fname); |
| 503 | + wfProfileIn( $fname ); |
504 | 504 | |
505 | 505 | $wgSolrTalker = new SolrTalker(); |
506 | 506 | |
507 | | - $query = $wgSolrTalker->queryChecker($query); |
508 | | - $xml = $wgSolrTalker->solrQuery($query, $offset, $limit, true, true); // Abfrage ok, ergebniss in XML |
| 507 | + $query = $wgSolrTalker->queryChecker( $query ); |
| 508 | + $xml = $wgSolrTalker->solrQuery( $query, $offset, $limit, true, true ); // Abfrage ok, ergebniss in XML |
509 | 509 | $totalHits = $xml->result['numFound']; |
510 | 510 | |
511 | | - $resultLines = array();; |
| 511 | + $resultLines = array(); ; |
512 | 512 | |
513 | | - $highl = $xml->xpath('//lst[@name="highlighting"]/lst'); |
| 513 | + $highl = $xml->xpath( '//lst[@name="highlighting"]/lst' ); |
514 | 514 | |
515 | 515 | $hli = 0; |
516 | 516 | |
517 | | - foreach ($xml->result->doc as $doc) { |
| 517 | + foreach ( $xml->result->doc as $doc ) { |
518 | 518 | |
519 | | - if (isset($highl[$hli]->arr)) { |
| 519 | + if ( isset( $highl[$hli]->arr ) ) { |
520 | 520 | |
521 | | - foreach ($highl[$hli]->arr as $feld) { |
522 | | - if (isset($feld['name'])) { |
| 521 | + foreach ( $highl[$hli]->arr as $feld ) { |
| 522 | + if ( isset( $feld['name'] ) ) { |
523 | 523 | |
524 | | - switch ($feld['name']) { |
| 524 | + switch ( $feld['name'] ) { |
525 | 525 | |
526 | 526 | case 'title': |
527 | 527 | $doc[]->highlight->title = $feld->str; |
— | — | @@ -542,20 +542,20 @@ |
543 | 543 | $interwiki = null; |
544 | 544 | |
545 | 545 | |
546 | | - $resultSet = new SolrSearchSet($method, $query, $resultLines, count($resultLines), $totalHits, |
547 | | - $suggestion, $info, $interwiki); |
| 546 | + $resultSet = new SolrSearchSet( $method, $query, $resultLines, count( $resultLines ), $totalHits, |
| 547 | + $suggestion, $info, $interwiki ); |
548 | 548 | |
549 | | - wfProfileOut($fname); |
| 549 | + wfProfileOut( $fname ); |
550 | 550 | return $resultSet; |
551 | 551 | } |
552 | 552 | |
553 | | - static function startsWith($source, $prefix) { |
554 | | - return strncmp($source, $prefix, strlen($prefix)) == 0; |
| 553 | + static function startsWith( $source, $prefix ) { |
| 554 | + return strncmp( $source, $prefix, strlen( $prefix ) ) == 0; |
555 | 555 | } |
556 | 556 | |
557 | 557 | /** |
558 | 558 | * Private constructor. Use SolrSearchSet::newFromQuery(). |
559 | | - * |
| 559 | + * |
560 | 560 | * @param string $method |
561 | 561 | * @param string $query |
562 | 562 | * @param array $lines |
— | — | @@ -565,7 +565,7 @@ |
566 | 566 | * @param string $info |
567 | 567 | * @access private |
568 | 568 | */ |
569 | | - function SolrSearchSet($method, $query, $lines, $resultCount, $totalHits = null, $suggestion = null, $info = null, $interwiki = null) { |
| 569 | + function SolrSearchSet( $method, $query, $lines, $resultCount, $totalHits = null, $suggestion = null, $info = null, $interwiki = null ) { |
570 | 570 | $this->mMethod = $method; |
571 | 571 | $this->mQuery = $query; |
572 | 572 | $this->mTotalHits = $totalHits; |
— | — | @@ -574,46 +574,46 @@ |
575 | 575 | $this->mPos = 0; |
576 | 576 | $this->mSuggestionQuery = null; |
577 | 577 | $this->mSuggestionSnippet = ''; |
578 | | - $this->parseSuggestion($suggestion); |
| 578 | + $this->parseSuggestion( $suggestion ); |
579 | 579 | $this->mInfo = $info; |
580 | 580 | $this->mInterwiki = $interwiki; |
581 | 581 | } |
582 | 582 | |
583 | 583 | /** Get suggestions from a suggestion result line */ |
584 | | - function parseSuggestion($suggestion) { |
585 | | - if (is_null($suggestion)) |
| 584 | + function parseSuggestion( $suggestion ) { |
| 585 | + if ( is_null( $suggestion ) ) |
586 | 586 | return; |
587 | 587 | // parse split points and highlight changes |
588 | | - list($dummy, $points, $sug) = explode(" ", $suggestion); |
589 | | - $sug = urldecode($sug); |
590 | | - $points = explode(",", substr($points, 1, -1)); |
591 | | - array_unshift($points, 0); |
| 588 | + list( $dummy, $points, $sug ) = explode( " ", $suggestion ); |
| 589 | + $sug = urldecode( $sug ); |
| 590 | + $points = explode( ",", substr( $points, 1, -1 ) ); |
| 591 | + array_unshift( $points, 0 ); |
592 | 592 | $suggestText = ""; |
593 | | - for ($i = 1; $i < count($points); $i+=2) { |
594 | | - $suggestText .= htmlspecialchars(substr($sug, $points[$i - 1], $points[$i] - $points[$i - 1])); |
595 | | - $suggestText .= '<em>' . htmlspecialchars(substr($sug, $points[$i], $points[$i + 1] - $points[$i])) . "</em>"; |
| 593 | + for ( $i = 1; $i < count( $points ); $i += 2 ) { |
| 594 | + $suggestText .= htmlspecialchars( substr( $sug, $points[$i - 1], $points[$i] - $points[$i - 1] ) ); |
| 595 | + $suggestText .= '<em>' . htmlspecialchars( substr( $sug, $points[$i], $points[$i + 1] - $points[$i] ) ) . "</em>"; |
596 | 596 | } |
597 | | - $suggestText .= htmlspecialchars(substr($sug, end($points))); |
| 597 | + $suggestText .= htmlspecialchars( substr( $sug, end( $points ) ) ); |
598 | 598 | |
599 | | - $this->mSuggestionQuery = $this->replaceGenericPrefixes($sug); |
600 | | - $this->mSuggestionSnippet = $this->replaceGenericPrefixes($suggestText); |
| 599 | + $this->mSuggestionQuery = $this->replaceGenericPrefixes( $sug ); |
| 600 | + $this->mSuggestionSnippet = $this->replaceGenericPrefixes( $suggestText ); |
601 | 601 | } |
602 | 602 | |
603 | 603 | /** replace prefixes like [2]: that are not in phrases */ |
604 | | - function replaceGenericPrefixes($text) { |
| 604 | + function replaceGenericPrefixes( $text ) { |
605 | 605 | $out = ""; |
606 | | - $phrases = explode('"', $text); |
607 | | - for ($i = 0; $i < count($phrases); $i+=2) { |
608 | | - $out .= preg_replace_callback('/\[([0-9]+)\]:/', array($this, 'genericPrefixCallback'), $phrases[$i]); |
609 | | - if ($i + 1 < count($phrases)) |
610 | | - $out .= '"' . $phrases[$i + 1] . '"'; // phrase text |
| 606 | + $phrases = explode( '"', $text ); |
| 607 | + for ( $i = 0; $i < count( $phrases ); $i += 2 ) { |
| 608 | + $out .= preg_replace_callback( '/\[([0-9]+)\]:/', array( $this, 'genericPrefixCallback' ), $phrases[$i] ); |
| 609 | + if ( $i + 1 < count( $phrases ) ) |
| 610 | + $out .= '"' . $phrases[$i + 1] . '"'; // phrase text |
611 | 611 | } |
612 | 612 | return $out; |
613 | 613 | } |
614 | 614 | |
615 | | - function genericPrefixCallback($matches) { |
| 615 | + function genericPrefixCallback( $matches ) { |
616 | 616 | global $wgContLang; |
617 | | - return $wgContLang->getFormattedNsText($matches[1]) . ":"; |
| 617 | + return $wgContLang->getFormattedNsText( $matches[1] ) . ":"; |
618 | 618 | } |
619 | 619 | |
620 | 620 | function numRows() { |
— | — | @@ -621,8 +621,8 @@ |
622 | 622 | } |
623 | 623 | |
624 | 624 | function termMatches() { |
625 | | - $resq = preg_replace("/\\[.*?\\]:/", " ", $this->mQuery); # generic prefixes |
626 | | - $resq = preg_replace("/all:/", " ", $resq); |
| 625 | + $resq = preg_replace( "/\\[.*?\\]:/", " ", $this->mQuery ); # generic prefixes |
| 626 | + $resq = preg_replace( "/all:/", " ", $resq ); |
627 | 627 | |
628 | 628 | // Fixme: this is ripped from SearchMySQL and probably kind of sucks, |
629 | 629 | // but it handles quoted phrase searches more or less correctly. |
— | — | @@ -631,22 +631,22 @@ |
632 | 632 | $regexes = array(); |
633 | 633 | $m = array(); |
634 | 634 | $lc = SearchEngine::legalSearchChars(); |
635 | | - if (preg_match_all('/([-+<>~]?)(([' . $lc . ']+)(\*?)|"[^"]*")/', $resq, $m, PREG_SET_ORDER)) { |
636 | | - foreach ($m as $terms) { |
637 | | - if (!empty($terms[3])) { |
| 635 | + if ( preg_match_all( '/([-+<>~]?)(([' . $lc . ']+)(\*?)|"[^"]*")/', $resq, $m, PREG_SET_ORDER ) ) { |
| 636 | + foreach ( $m as $terms ) { |
| 637 | + if ( !empty( $terms[3] ) ) { |
638 | 638 | // Match individual terms in result highlighting... |
639 | | - $regexp = preg_quote($terms[3], '/'); |
640 | | - if ($terms[4]) |
| 639 | + $regexp = preg_quote( $terms[3], '/' ); |
| 640 | + if ( $terms[4] ) |
641 | 641 | $regexp .= "[0-9A-Za-z_]+"; |
642 | 642 | } else { |
643 | 643 | // Match the quoted term in result highlighting... |
644 | | - $regexp = preg_quote(str_replace('"', '', $terms[2]), '/'); |
| 644 | + $regexp = preg_quote( str_replace( '"', '', $terms[2] ), '/' ); |
645 | 645 | } |
646 | 646 | $regexes[] = $regexp; |
647 | 647 | } |
648 | | - wfDebug(__METHOD__ . ': Match with /' . implode('|', $regexes) . "/\n"); |
| 648 | + wfDebug( __METHOD__ . ': Match with /' . implode( '|', $regexes ) . "/\n" ); |
649 | 649 | } else { |
650 | | - wfDebug("Can't understand search query '{$resq}'\n"); |
| 650 | + wfDebug( "Can't understand search query '{$resq}'\n" ); |
651 | 651 | } |
652 | 652 | return $regexes; |
653 | 653 | } |
— | — | @@ -655,12 +655,12 @@ |
656 | 656 | * Stupid hack around PHP's limited lambda support |
657 | 657 | * @access private |
658 | 658 | */ |
659 | | - function regexQuote($term) { |
660 | | - return preg_quote($term, '/'); |
| 659 | + function regexQuote( $term ) { |
| 660 | + return preg_quote( $term, '/' ); |
661 | 661 | } |
662 | 662 | |
663 | 663 | function hasResults() { |
664 | | - return count($this->mResults) > 0; |
| 664 | + return count( $this->mResults ) > 0; |
665 | 665 | } |
666 | 666 | |
667 | 667 | /** |
— | — | @@ -678,12 +678,12 @@ |
679 | 679 | |
680 | 680 | /** |
681 | 681 | * Return information about how and from where the results were fetched, |
682 | | - * should be useful for diagnostics and debugging |
| 682 | + * should be useful for diagnostics and debugging |
683 | 683 | * |
684 | 684 | * @return string |
685 | 685 | */ |
686 | 686 | function getInfo() { |
687 | | - if (is_null($this->mInfo)) |
| 687 | + if ( is_null( $this->mInfo ) ) |
688 | 688 | return null; |
689 | 689 | return "Search results fetched via " . $this->mInfo; |
690 | 690 | } |
— | — | @@ -705,7 +705,7 @@ |
706 | 706 | * @access public |
707 | 707 | */ |
708 | 708 | function hasSuggestion() { |
709 | | - return is_string($this->mSuggestionQuery) && $this->mSuggestionQuery != ''; |
| 709 | + return is_string( $this->mSuggestionQuery ) && $this->mSuggestionQuery != ''; |
710 | 710 | } |
711 | 711 | |
712 | 712 | function getSuggestionQuery() { |
— | — | @@ -723,9 +723,9 @@ |
724 | 724 | * @abstract |
725 | 725 | */ |
726 | 726 | function next() { |
727 | | - if ($this->mPos < $this->mResultCount) { |
| 727 | + if ( $this->mPos < $this->mResultCount ) { |
728 | 728 | $this->mPos++; |
729 | | - return new SolrResult($this->mResults[$this->mPos - 1], $this->mMethod); |
| 729 | + return new SolrResult( $this->mResults[$this->mPos - 1], $this->mMethod ); |
730 | 730 | } else { |
731 | 731 | return null; |
732 | 732 | } |
Index: trunk/extensions/SolrStore/SolrSearchFieldSet.php |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | 4 | * File holding the SolrSearchFieldSet class |
5 | | - * |
| 5 | + * |
6 | 6 | * @ingroup SolrStore |
7 | 7 | * @file |
8 | 8 | * @author Simon Bachenberg |
— | — | @@ -9,13 +9,13 @@ |
10 | 10 | |
11 | 11 | /** |
12 | 12 | * TODO: Insert class description |
13 | | - * |
| 13 | + * |
14 | 14 | * To create a SearchSet for your Wiki add the Following Lines to you LocalSettings.php |
15 | 15 | * $wgSolrFields = array( |
16 | 16 | * new SolrSearchFieldSet('<Name of the SearchSet>', '<Semicolon Seperated List of your Semantic Propertys>', ''<Semicolon Seperated List of the Lable for your Fields>', '<Extra Query Parameters>'), |
17 | 17 | * new SolrSearchFieldSet('Institution', 'has_name; has_country', 'Name, Country', ' AND category:Event') |
18 | 18 | * ); |
19 | | - * |
| 19 | + * |
20 | 20 | * @ingroup SolrStore |
21 | 21 | */ |
22 | 22 | class SolrSearchFieldSet { |
— | — | @@ -25,10 +25,10 @@ |
26 | 26 | var $mLable; |
27 | 27 | var $mQuery; |
28 | 28 | |
29 | | - public function __construct($name, $fields = 'search', $lable = 'Alles', $query = null) { |
| 29 | + public function __construct( $name, $fields = 'search', $lable = 'Alles', $query = null ) { |
30 | 30 | $this->mName = $name; |
31 | | - $this->mFields = explode(';', $fields); |
32 | | - $this->mLable = explode(';', $lable); |
| 31 | + $this->mFields = explode( ';', $fields ); |
| 32 | + $this->mLable = explode( ';', $lable ); |
33 | 33 | $this->mQuery = $query; |
34 | 34 | } |
35 | 35 | |
— | — | @@ -48,19 +48,19 @@ |
49 | 49 | return $this->mQuery; |
50 | 50 | } |
51 | 51 | |
52 | | - public function setName($value) { |
| 52 | + public function setName( $value ) { |
53 | 53 | $this->mName = $value; |
54 | 54 | } |
55 | 55 | |
56 | | - public function setFields($value) { |
| 56 | + public function setFields( $value ) { |
57 | 57 | $this->mFields = $value; |
58 | 58 | } |
59 | 59 | |
60 | | - public function setLable($value) { |
| 60 | + public function setLable( $value ) { |
61 | 61 | $this->mLable = $value; |
62 | 62 | } |
63 | 63 | |
64 | | - public function setQuery($value) { |
| 64 | + public function setQuery( $value ) { |
65 | 65 | $this->mQuery = $value; |
66 | 66 | } |
67 | 67 | |
Index: trunk/extensions/SolrStore/SpecialSolrSearch.php |
— | — | @@ -1,9 +1,9 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | 4 | * File holding the SpecialSolrSearch class |
5 | | - * |
| 5 | + * |
6 | 6 | * This is the SpecialPage, displaying the SearchSets and Results |
7 | | - * |
| 7 | + * |
8 | 8 | * @ingroup SolrStore |
9 | 9 | * @file |
10 | 10 | * @author Simon Bachenberg |
— | — | @@ -11,7 +11,7 @@ |
12 | 12 | |
13 | 13 | /** |
14 | 14 | * TODO: Insert class description |
15 | | - * |
| 15 | + * |
16 | 16 | * @ingroup SolrStore |
17 | 17 | */ |
18 | 18 | class SpecialSolrSearch extends SpecialPage { |
— | — | @@ -24,27 +24,27 @@ |
25 | 25 | * @param $user User |
26 | 26 | */ |
27 | 27 | public function __construct() { |
28 | | - parent::__construct("SolrSearch"); |
| 28 | + parent::__construct( "SolrSearch" ); |
29 | 29 | global $wgRequest, $wgUser, $wgOut, $wgSolrFields; |
30 | 30 | $user = $wgUser; |
31 | 31 | $request = $wgRequest; |
32 | | - list( $this->limit, $this->offset ) = $request->getLimitOffset(20, 'searchlimit'); |
| 32 | + list( $this->limit, $this->offset ) = $request->getLimitOffset( 20, 'searchlimit' ); |
33 | 33 | |
34 | 34 | $this->sk = $user->getSkin(); |
35 | 35 | $this->didYouMeanHtml = ''; # html of did you mean... link |
36 | 36 | } |
37 | 37 | |
38 | | - function execute($par) { |
| 38 | + function execute( $par ) { |
39 | 39 | global $wgRequest, $wgUser, $wgOut, $wgSolrFields; |
40 | 40 | |
41 | 41 | $this->setHeaders(); |
42 | | - $SpecialSolrSearch = new SpecialSolrSearch($wgRequest, $wgUser); |
| 42 | + $SpecialSolrSearch = new SpecialSolrSearch( $wgRequest, $wgUser ); |
43 | 43 | |
44 | 44 | # Get request data from, e.g. |
45 | | - $param = $wgRequest->getText('param'); |
| 45 | + $param = $wgRequest->getText( 'param' ); |
46 | 46 | |
47 | | - foreach ($wgSolrFields as $set) { |
48 | | - if ($par == $set->getName()) { |
| 47 | + foreach ( $wgSolrFields as $set ) { |
| 48 | + if ( $par == $set->getName() ) { |
49 | 49 | $fieldSet = $set; |
50 | 50 | } |
51 | 51 | } |
— | — | @@ -52,29 +52,29 @@ |
53 | 53 | # ... |
54 | 54 | // Strip underscores from title parameter; most of the time we'll want |
55 | 55 | // text form here. But don't strip underscores from actual text params! |
56 | | - $titleParam = str_replace('_', ' ', $par); |
| 56 | + $titleParam = str_replace( '_', ' ', $par ); |
57 | 57 | // Fetch the search term |
58 | 58 | // $search = str_replace("\n", " ", $wgRequest->getText('solrsearch', $titleParam)); |
59 | 59 | |
60 | | - if (!isset($fieldSet)) { |
| 60 | + if ( !isset( $fieldSet ) ) { |
61 | 61 | $SpecialSolrSearch->showFieldSets(); |
62 | 62 | } else { |
63 | 63 | $lable = $fieldSet->getLable(); |
64 | 64 | $firstTimeHere = true; |
65 | | - foreach ($fieldSet->getFields() as $field) { |
66 | | - if ($firstTimeHere) { |
67 | | - $newLable ['solr' . trim($field)] = trim($lable[0]); |
| 65 | + foreach ( $fieldSet->getFields() as $field ) { |
| 66 | + if ( $firstTimeHere ) { |
| 67 | + $newLable ['solr' . trim( $field )] = trim( $lable[0] ); |
68 | 68 | $firstTimeHere = false; |
69 | 69 | } else { |
70 | | - $newLable ['solr' . trim($field)] = trim(next($lable)); |
| 70 | + $newLable ['solr' . trim( $field )] = trim( next( $lable ) ); |
71 | 71 | } |
72 | 72 | |
73 | | - $newFields ['solr' . trim($field)] = $wgRequest->getText('solr' . trim($field)); |
| 73 | + $newFields ['solr' . trim( $field )] = $wgRequest->getText( 'solr' . trim( $field ) ); |
74 | 74 | } |
75 | | - $fieldSet->setFields($newFields); |
76 | | - $fieldSet->setLable($newLable); |
| 75 | + $fieldSet->setFields( $newFields ); |
| 76 | + $fieldSet->setLable( $newLable ); |
77 | 77 | |
78 | | - $SpecialSolrSearch->showResults($fieldSet); |
| 78 | + $SpecialSolrSearch->showResults( $fieldSet ); |
79 | 79 | } |
80 | 80 | } |
81 | 81 | |
— | — | @@ -83,92 +83,92 @@ |
84 | 84 | */ |
85 | 85 | public function showFieldSets() { |
86 | 86 | global $wgOut, $wgUser, $wgDisableTextSearch, $wgContLang, $wgScript, $wgSolrFields; |
87 | | - wfProfileIn(__METHOD__); |
| 87 | + wfProfileIn( __METHOD__ ); |
88 | 88 | |
89 | 89 | $sk = $wgUser->getSkin(); |
90 | 90 | |
91 | 91 | |
92 | | - $wgOut->setPageTitle(wfMsg('searchFieldSets')); |
93 | | - $wgOut->setHTMLTitle(wfMsg('pagetitle', wfMsg('searchFieldSets-title', 'SolrSearch: Select FieldSet'))); |
| 92 | + $wgOut->setPageTitle( wfMsg( 'searchFieldSets' ) ); |
| 93 | + $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'searchFieldSets-title', 'SolrSearch: Select FieldSet' ) ) ); |
94 | 94 | |
95 | | - $wgOut->setArticleRelated(false); |
96 | | - $wgOut->addHtml('<div class="solrsearch-fieldset">'); |
97 | | - $wgOut->addHtml(wfMsg('searchFieldSets-select')); |
98 | | - $wgOut->addHtml('<ul>'); |
| 95 | + $wgOut->setArticleRelated( false ); |
| 96 | + $wgOut->addHtml( '<div class="solrsearch-fieldset">' ); |
| 97 | + $wgOut->addHtml( wfMsg( 'searchFieldSets-select' ) ); |
| 98 | + $wgOut->addHtml( '<ul>' ); |
99 | 99 | |
100 | | - //TODO: If no SearchSets exist, provide a shot Manual how to create some! |
101 | | - foreach ($wgSolrFields as $set) { |
| 100 | + // TODO: If no SearchSets exist, provide a shot Manual how to create some! |
| 101 | + foreach ( $wgSolrFields as $set ) { |
102 | 102 | $name = $set->getName(); |
103 | | - $wgOut->addHtml("<li><a href=\"$wgScript/Special:SolrSearch/$name\">$name</a></li>"); |
| 103 | + $wgOut->addHtml( "<li><a href=\"$wgScript/Special:SolrSearch/$name\">$name</a></li>" ); |
104 | 104 | } |
105 | | - $wgOut->addHtml('</ul>'); |
106 | | - $wgOut->addHtml("</div>"); |
| 105 | + $wgOut->addHtml( '</ul>' ); |
| 106 | + $wgOut->addHtml( "</div>" ); |
107 | 107 | |
108 | | - wfProfileOut(__METHOD__); |
| 108 | + wfProfileOut( __METHOD__ ); |
109 | 109 | } |
110 | | - |
| 110 | + |
111 | 111 | /** |
112 | 112 | * @param $fieldSet String |
113 | 113 | */ |
114 | | - public function showResults($fieldSet) { |
| 114 | + public function showResults( $fieldSet ) { |
115 | 115 | global $wgOut, $wgUser, $wgDisableTextSearch, $wgContLang, $wgScript; |
116 | | - wfProfileIn(__METHOD__); |
| 116 | + wfProfileIn( __METHOD__ ); |
117 | 117 | |
118 | 118 | $sk = $wgUser->getSkin(); |
119 | 119 | |
120 | 120 | $this->searchEngine = SearchEngine::create(); |
121 | 121 | $search = & $this->searchEngine; |
122 | | - $search->setLimitOffset($this->limit, $this->offset); |
| 122 | + $search->setLimitOffset( $this->limit, $this->offset ); |
123 | 123 | |
124 | | - $this->setupPage($fieldSet); |
| 124 | + $this->setupPage( $fieldSet ); |
125 | 125 | |
126 | | - $t = Title::newFromText($fieldSet->getName()); |
| 126 | + $t = Title::newFromText( $fieldSet->getName() ); |
127 | 127 | |
128 | | - //DO we have Title matches |
| 128 | + // DO we have Title matches |
129 | 129 | $fields = $fieldSet->getFields(); |
130 | 130 | |
131 | | - //BUILD SOLR QUERY STRING FROM DA FIELDS |
132 | | - if (isset($fields['solrsearch'])) { |
| 131 | + // BUILD SOLR QUERY STRING FROM DA FIELDS |
| 132 | + if ( isset( $fields['solrsearch'] ) ) { |
133 | 133 | $query = $fields['solrsearch']; |
134 | 134 | } else { |
135 | 135 | $query = ''; |
136 | 136 | } |
137 | 137 | |
138 | 138 | |
139 | | - foreach ($fields as $key => $value) { |
140 | | - if ($key != 'solrsearch' && !empty($value)) { |
141 | | - $query = trim($query).' '.trim(substr($key, 4)) . ':' . '(' . ($value) . ')'; |
| 139 | + foreach ( $fields as $key => $value ) { |
| 140 | + if ( $key != 'solrsearch' && !empty( $value ) ) { |
| 141 | + $query = trim( $query ) . ' ' . trim( substr( $key, 4 ) ) . ':' . '(' . ( $value ) . ')'; |
142 | 142 | } |
143 | 143 | } |
144 | 144 | |
145 | | - if (!empty($query)) { |
146 | | - $query .=$fieldSet->getQuery(); |
| 145 | + if ( !empty( $query ) ) { |
| 146 | + $query .= $fieldSet->getQuery(); |
147 | 147 | } |
148 | | - |
149 | | - $titleMatches = $search->searchTitle($query); |
150 | 148 | |
151 | | - if (!($titleMatches instanceof SearchResultTooMany)) |
152 | | - $textMatches = $search->searchText($query); |
| 149 | + $titleMatches = $search->searchTitle( $query ); |
153 | 150 | |
| 151 | + if ( !( $titleMatches instanceof SearchResultTooMany ) ) |
| 152 | + $textMatches = $search->searchText( $query ); |
| 153 | + |
154 | 154 | // did you mean... suggestions |
155 | | - if ($textMatches && $textMatches->hasSuggestion()) { |
156 | | - $st = SpecialPage::getTitleFor('SolrSearch'); |
| 155 | + if ( $textMatches && $textMatches->hasSuggestion() ) { |
| 156 | + $st = SpecialPage::getTitleFor( 'SolrSearch' ); |
157 | 157 | |
158 | 158 | # mirror Go/Search behaviour of original request .. |
159 | | - $didYouMeanParams = array('solrsearch' => $textMatches->getSuggestionQuery()); |
| 159 | + $didYouMeanParams = array( 'solrsearch' => $textMatches->getSuggestionQuery() ); |
160 | 160 | |
161 | 161 | $stParams = $didYouMeanParams; |
162 | 162 | |
163 | 163 | $suggestionSnippet = $textMatches->getSuggestionSnippet(); |
164 | 164 | |
165 | | - if ($suggestionSnippet == '') |
| 165 | + if ( $suggestionSnippet == '' ) |
166 | 166 | $suggestionSnippet = null; |
167 | 167 | |
168 | 168 | $suggestLink = $sk->linkKnown( |
169 | 169 | $st, $suggestionSnippet, array(), $stParams |
170 | 170 | ); |
171 | 171 | |
172 | | - $this->didYouMeanHtml = '<div class="searchdidyoumean">' . wfMsg('search-suggest', $suggestLink) . '</div>'; |
| 172 | + $this->didYouMeanHtml = '<div class="searchdidyoumean">' . wfMsg( 'search-suggest', $suggestLink ) . '</div>'; |
173 | 173 | } |
174 | 174 | // start rendering the page |
175 | 175 | $wgOut->addHtml( |
— | — | @@ -181,28 +181,28 @@ |
182 | 182 | ) |
183 | 183 | ); |
184 | 184 | $wgOut->addHtml( |
185 | | - Xml::openElement('table', array('id' => 'mw-search-top-table', 'border' => 0, 'cellpadding' => 0, 'cellspacing' => 0)) . |
186 | | - Xml::openElement('tr') . |
187 | | - Xml::openElement('td') . "\n" . |
188 | | - $this->shortDialog($fieldSet) . |
189 | | - Xml::closeElement('td') . |
190 | | - Xml::closeElement('tr') . |
191 | | - Xml::closeElement('table') |
| 185 | + Xml::openElement( 'table', array( 'id' => 'mw-search-top-table', 'border' => 0, 'cellpadding' => 0, 'cellspacing' => 0 ) ) . |
| 186 | + Xml::openElement( 'tr' ) . |
| 187 | + Xml::openElement( 'td' ) . "\n" . |
| 188 | + $this->shortDialog( $fieldSet ) . |
| 189 | + Xml::closeElement( 'td' ) . |
| 190 | + Xml::closeElement( 'tr' ) . |
| 191 | + Xml::closeElement( 'table' ) |
192 | 192 | ); |
193 | 193 | |
194 | 194 | // Sometimes the search engine knows there are too many hits |
195 | | - if ($titleMatches instanceof SearchResultTooMany) { |
196 | | - $wgOut->addWikiText('==' . wfMsg('toomanymatches') . "==\n"); |
197 | | - wfProfileOut(__METHOD__); |
| 195 | + if ( $titleMatches instanceof SearchResultTooMany ) { |
| 196 | + $wgOut->addWikiText( '==' . wfMsg( 'toomanymatches' ) . "==\n" ); |
| 197 | + wfProfileOut( __METHOD__ ); |
198 | 198 | return; |
199 | 199 | } |
200 | 200 | |
201 | | - $filePrefix = $wgContLang->getFormattedNsText(NS_FILE) . ':'; |
202 | | - if (trim($query) === '' || $filePrefix === trim($query)) { |
203 | | - $wgOut->addHTML($this->formHeader($query, 0, 0)); |
204 | | - $wgOut->addHTML('</form>'); |
| 201 | + $filePrefix = $wgContLang->getFormattedNsText( NS_FILE ) . ':'; |
| 202 | + if ( trim( $query ) === '' || $filePrefix === trim( $query ) ) { |
| 203 | + $wgOut->addHTML( $this->formHeader( $query, 0, 0 ) ); |
| 204 | + $wgOut->addHTML( '</form>' ); |
205 | 205 | // Empty query -- straight view of search form |
206 | | - wfProfileOut(__METHOD__); |
| 206 | + wfProfileOut( __METHOD__ ); |
207 | 207 | return; |
208 | 208 | } |
209 | 209 | // Get number of results |
— | — | @@ -212,105 +212,105 @@ |
213 | 213 | $num = $titleMatchesNum + $textMatchesNum; |
214 | 214 | |
215 | 215 | // Get total actual results (after second filtering, if any) |
216 | | - $numTitleMatches = $titleMatches && !is_null($titleMatches->getTotalHits()) ? |
| 216 | + $numTitleMatches = $titleMatches && !is_null( $titleMatches->getTotalHits() ) ? |
217 | 217 | $titleMatches->getTotalHits() : $titleMatchesNum; |
218 | | - $numTextMatches = $textMatches && !is_null($textMatches->getTotalHits()) ? |
| 218 | + $numTextMatches = $textMatches && !is_null( $textMatches->getTotalHits() ) ? |
219 | 219 | $textMatches->getTotalHits() : $textMatchesNum; |
220 | 220 | |
221 | 221 | // get total number of results if backend can calculate it |
222 | 222 | $totalRes = 0; |
223 | | - if ($titleMatches && !is_null($titleMatches->getTotalHits())) |
| 223 | + if ( $titleMatches && !is_null( $titleMatches->getTotalHits() ) ) |
224 | 224 | $totalRes += $titleMatches->getTotalHits(); |
225 | | - if ($textMatches && !is_null($textMatches->getTotalHits())) |
| 225 | + if ( $textMatches && !is_null( $textMatches->getTotalHits() ) ) |
226 | 226 | $totalRes += $textMatches->getTotalHits(); |
227 | 227 | // show number of results and current offset |
228 | | - $wgOut->addHTML($this->formHeader($query, $num, $totalRes)); |
| 228 | + $wgOut->addHTML( $this->formHeader( $query, $num, $totalRes ) ); |
229 | 229 | |
230 | | - $wgOut->addHtml(Xml::closeElement('form')); |
231 | | - $wgOut->addHtml("<div class='searchresults'>"); |
| 230 | + $wgOut->addHtml( Xml::closeElement( 'form' ) ); |
| 231 | + $wgOut->addHtml( "<div class='searchresults'>" ); |
232 | 232 | |
233 | 233 | // prev/next links |
234 | | - if ($num || $this->offset) { |
| 234 | + if ( $num || $this->offset ) { |
235 | 235 | // Show the create link ahead |
236 | | - $this->showCreateLink($t); |
237 | | - $prevnext = wfViewPrevNext($this->offset, $this->limit, SpecialPage::getTitleFor('SolrSearch'), wfArrayToCGI(array('solrsearch' => $query)), max($titleMatchesNum, $textMatchesNum) < $this->limit |
| 236 | + $this->showCreateLink( $t ); |
| 237 | + $prevnext = wfViewPrevNext( $this->offset, $this->limit, SpecialPage::getTitleFor( 'SolrSearch' ), wfArrayToCGI( array( 'solrsearch' => $query ) ), max( $titleMatchesNum, $textMatchesNum ) < $this->limit |
238 | 238 | ); |
239 | | - //$wgOut->addHTML( "<p class='mw-search-pager-top'>{$prevnext}</p>\n" ); |
240 | | - wfRunHooks('SpecialSolrSearchResults', array($fieldSet, &$titleMatches, &$textMatches)); |
| 239 | + // $wgOut->addHTML( "<p class='mw-search-pager-top'>{$prevnext}</p>\n" ); |
| 240 | + wfRunHooks( 'SpecialSolrSearchResults', array( $fieldSet, &$titleMatches, &$textMatches ) ); |
241 | 241 | } else { |
242 | | - wfRunHooks('SpecialSolrSearchNoResults', array($fieldSet)); |
| 242 | + wfRunHooks( 'SpecialSolrSearchNoResults', array( $fieldSet ) ); |
243 | 243 | } |
244 | 244 | |
245 | | - if ($titleMatches) { |
246 | | - if ($numTitleMatches > 0) { |
247 | | - $wgOut->wrapWikiMsg("==$1==\n", 'titlematches'); |
248 | | - $wgOut->addHTML($this->showMatches($titleMatches)); |
| 245 | + if ( $titleMatches ) { |
| 246 | + if ( $numTitleMatches > 0 ) { |
| 247 | + $wgOut->wrapWikiMsg( "==$1==\n", 'titlematches' ); |
| 248 | + $wgOut->addHTML( $this->showMatches( $titleMatches ) ); |
249 | 249 | } |
250 | 250 | $titleMatches->free(); |
251 | 251 | } |
252 | | - if ($textMatches) { |
| 252 | + if ( $textMatches ) { |
253 | 253 | // output appropriate heading |
254 | | - if ($numTextMatches > 0 && $numTitleMatches > 0) { |
| 254 | + if ( $numTextMatches > 0 && $numTitleMatches > 0 ) { |
255 | 255 | // if no title matches the heading is redundant |
256 | | - $wgOut->wrapWikiMsg("==$1==\n", 'textmatches'); |
257 | | - } elseif ($totalRes == 0) { |
| 256 | + $wgOut->wrapWikiMsg( "==$1==\n", 'textmatches' ); |
| 257 | + } elseif ( $totalRes == 0 ) { |
258 | 258 | # Don't show the 'no text matches' if we received title matches |
259 | 259 | # $wgOut->wrapWikiMsg( "==$1==\n", 'notextmatches' ); |
260 | 260 | } |
261 | 261 | |
262 | 262 | // show results |
263 | | - if ($numTextMatches > 0) { |
264 | | - $wgOut->addHTML($this->showMatches($textMatches)); |
| 263 | + if ( $numTextMatches > 0 ) { |
| 264 | + $wgOut->addHTML( $this->showMatches( $textMatches ) ); |
265 | 265 | } |
266 | 266 | |
267 | 267 | $textMatches->free(); |
268 | 268 | } |
269 | 269 | |
270 | | - $wgOut->addHtml("</div>"); |
| 270 | + $wgOut->addHtml( "</div>" ); |
271 | 271 | |
272 | | - if ($num || $this->offset) { |
273 | | - $wgOut->addHTML("<p class='mw-search-pager-bottom'>{$prevnext}</p>\n"); |
| 272 | + if ( $num || $this->offset ) { |
| 273 | + $wgOut->addHTML( "<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" ); |
274 | 274 | } |
275 | | - wfProfileOut(__METHOD__); |
| 275 | + wfProfileOut( __METHOD__ ); |
276 | 276 | } |
277 | 277 | |
278 | | - protected function showCreateLink($t) { |
| 278 | + protected function showCreateLink( $t ) { |
279 | 279 | global $wgOut; |
280 | 280 | |
281 | 281 | // show direct page/create link if applicable |
282 | 282 | $messageName = null; |
283 | | - if (!is_null($t)) { |
284 | | - if ($t->isKnown()) { |
| 283 | + if ( !is_null( $t ) ) { |
| 284 | + if ( $t->isKnown() ) { |
285 | 285 | $messageName = 'searchmenu-exists'; |
286 | | - } elseif ($t->userCan('create')) { |
| 286 | + } elseif ( $t->userCan( 'create' ) ) { |
287 | 287 | $messageName = 'searchmenu-new'; |
288 | 288 | } else { |
289 | 289 | $messageName = 'searchmenu-new-nocreate'; |
290 | 290 | } |
291 | 291 | } |
292 | | - if ($messageName) { |
293 | | - $wgOut->wrapWikiMsg("<p class=\"mw-search-createlink\">\n$1</p>", array($messageName, wfEscapeWikiText($t->getPrefixedText()))); |
| 292 | + if ( $messageName ) { |
| 293 | + $wgOut->wrapWikiMsg( "<p class=\"mw-search-createlink\">\n$1</p>", array( $messageName, wfEscapeWikiText( $t->getPrefixedText() ) ) ); |
294 | 294 | } else { |
295 | 295 | // preserve the paragraph for margins etc... |
296 | | - $wgOut->addHtml('<p></p>'); |
| 296 | + $wgOut->addHtml( '<p></p>' ); |
297 | 297 | } |
298 | 298 | } |
299 | 299 | |
300 | 300 | /** |
301 | 301 | * |
302 | 302 | */ |
303 | | - protected function setupPage($fieldSet) { |
| 303 | + protected function setupPage( $fieldSet ) { |
304 | 304 | global $wgOut; |
305 | 305 | |
306 | | - if (!empty($fieldSet)) { |
307 | | - $wgOut->setPageTitle(wfMsg('searchresults')); |
308 | | - $wgOut->setHTMLTitle(wfMsg('pagetitle', wfMsg('searchresults-title', $fieldSet->getName()))); |
| 306 | + if ( !empty( $fieldSet ) ) { |
| 307 | + $wgOut->setPageTitle( wfMsg( 'searchresults' ) ); |
| 308 | + $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'searchresults-title', $fieldSet->getName() ) ) ); |
309 | 309 | } |
310 | | - $wgOut->setArticleRelated(false); |
311 | | - $wgOut->setRobotPolicy('noindex,nofollow'); |
| 310 | + $wgOut->setArticleRelated( false ); |
| 311 | + $wgOut->setRobotPolicy( 'noindex,nofollow' ); |
312 | 312 | // add javascript specific to special:search |
313 | | - $wgOut->addModules('mediawiki.legacy.search'); |
314 | | - $wgOut->addModules('mediawiki.special.search'); |
| 313 | + $wgOut->addModules( 'mediawiki.legacy.search' ); |
| 314 | + $wgOut->addModules( 'mediawiki.special.search' ); |
315 | 315 | } |
316 | 316 | |
317 | 317 | /** |
— | — | @@ -318,27 +318,27 @@ |
319 | 319 | * |
320 | 320 | * @param $matches SearchResultSet |
321 | 321 | */ |
322 | | - protected function showMatches(&$matches) { |
| 322 | + protected function showMatches( &$matches ) { |
323 | 323 | global $wgContLang; |
324 | | - wfProfileIn(__METHOD__); |
| 324 | + wfProfileIn( __METHOD__ ); |
325 | 325 | |
326 | | - $fieldSets = $wgContLang->convertForSearchResult($matches->termMatches()); |
| 326 | + $fieldSets = $wgContLang->convertForSearchResult( $matches->termMatches() ); |
327 | 327 | |
328 | 328 | $out = ""; |
329 | 329 | $infoLine = $matches->getInfo(); |
330 | | - if (!is_null($infoLine)) { |
| 330 | + if ( !is_null( $infoLine ) ) { |
331 | 331 | $out .= "\n<!-- {$infoLine} -->\n"; |
332 | 332 | } |
333 | 333 | $out .= "<ul class='mw-search-results'>\n"; |
334 | 334 | $xxx = 0; |
335 | | - while ($result = $matches->next()) { |
336 | | - $out .= $this->showHit($result, $fieldSets); |
| 335 | + while ( $result = $matches->next() ) { |
| 336 | + $out .= $this->showHit( $result, $fieldSets ); |
337 | 337 | } |
338 | 338 | $out .= "</ul>\n"; |
339 | 339 | |
340 | 340 | // convert the whole thing to desired language variant |
341 | | - $out = $wgContLang->convert($out); |
342 | | - wfProfileOut(__METHOD__); |
| 341 | + $out = $wgContLang->convert( $out ); |
| 342 | + wfProfileOut( __METHOD__ ); |
343 | 343 | return $out; |
344 | 344 | } |
345 | 345 | |
— | — | @@ -348,119 +348,119 @@ |
349 | 349 | * @param $result SearchResult |
350 | 350 | * @param $fieldSets Array: terms to highlight |
351 | 351 | */ |
352 | | - protected function showHit($result, $fieldSets) { |
| 352 | + protected function showHit( $result, $fieldSets ) { |
353 | 353 | global $wgLang, $wgUser; |
354 | | - wfProfileIn(__METHOD__); |
| 354 | + wfProfileIn( __METHOD__ ); |
355 | 355 | |
356 | | - if ($result->isBrokenTitle()) { |
357 | | - wfProfileOut(__METHOD__); |
| 356 | + if ( $result->isBrokenTitle() ) { |
| 357 | + wfProfileOut( __METHOD__ ); |
358 | 358 | return "<!-- Broken link in search result -->\n"; |
359 | 359 | } |
360 | 360 | |
361 | 361 | $sk = $wgUser->getSkin(); |
362 | 362 | $t = $result->getTitle(); |
363 | 363 | |
364 | | - $titleSnippet = $result->getTitleSnippet($fieldSets); |
| 364 | + $titleSnippet = $result->getTitleSnippet( $fieldSets ); |
365 | 365 | |
366 | | - if ($titleSnippet == '') |
| 366 | + if ( $titleSnippet == '' ) |
367 | 367 | $titleSnippet = null; |
368 | 368 | |
369 | 369 | $link_t = clone $t; |
370 | 370 | |
371 | | - wfRunHooks('ShowSearchHitTitle', array(&$link_t, &$titleSnippet, $result, $fieldSets, $this)); |
| 371 | + wfRunHooks( 'ShowSearchHitTitle', array( &$link_t, &$titleSnippet, $result, $fieldSets, $this ) ); |
372 | 372 | |
373 | 373 | $link = $this->sk->linkKnown( |
374 | 374 | $link_t, $titleSnippet |
375 | 375 | ); |
376 | 376 | // FÜLLEN |
377 | | - //If page content is not readable, just return the title. |
378 | | - //This is not quite safe, but better than showing excerpts from non-readable pages |
379 | | - //Note that hiding the entry entirely would screw up paging. |
| 377 | + // If page content is not readable, just return the title. |
| 378 | + // This is not quite safe, but better than showing excerpts from non-readable pages |
| 379 | + // Note that hiding the entry entirely would screw up paging. |
380 | 380 | // ---- HIER |
381 | | - if (!$t->userCanRead()) { |
382 | | - wfProfileOut(__METHOD__); |
| 381 | + if ( !$t->userCanRead() ) { |
| 382 | + wfProfileOut( __METHOD__ ); |
383 | 383 | return "<li>{$link}</li>\n"; |
384 | 384 | } |
385 | | - //return "<li>{$link}</li>\n"; |
| 385 | + // return "<li>{$link}</li>\n"; |
386 | 386 | // If the page doesn't *exist*... our search index is out of date. |
387 | 387 | // The least confusing at this point is to drop the result. |
388 | 388 | // You may get less results, but... oh well. :P |
389 | 389 | // ---- HIER |
390 | | - if ($result->isMissingRevision()) { |
391 | | - wfProfileOut(__METHOD__); |
392 | | - return "<!-- missing page " . htmlspecialchars($t->getPrefixedText()) . "-->\n"; |
| 390 | + if ( $result->isMissingRevision() ) { |
| 391 | + wfProfileOut( __METHOD__ ); |
| 392 | + return "<!-- missing page " . htmlspecialchars( $t->getPrefixedText() ) . "-->\n"; |
393 | 393 | } |
394 | 394 | |
395 | 395 | // format redirects / relevant sections |
396 | 396 | $redirectTitle = $result->getRedirectTitle(); |
397 | | - $redirectText = $result->getRedirectSnippet($fieldSets); |
| 397 | + $redirectText = $result->getRedirectSnippet( $fieldSets ); |
398 | 398 | $sectionTitle = $result->getSectionTitle(); |
399 | | - $sectionText = $result->getSectionSnippet($fieldSets); |
| 399 | + $sectionText = $result->getSectionSnippet( $fieldSets ); |
400 | 400 | $redirect = ''; |
401 | 401 | |
402 | | - if (!is_null($redirectTitle)) { |
403 | | - if ($redirectText == '') |
| 402 | + if ( !is_null( $redirectTitle ) ) { |
| 403 | + if ( $redirectText == '' ) |
404 | 404 | $redirectText = null; |
405 | 405 | |
406 | 406 | $redirect = "<span class='searchalttitle'>" . |
407 | | - wfMsg('search-redirect', $this->sk->linkKnown($redirectTitle, $redirectText)) . |
| 407 | + wfMsg( 'search-redirect', $this->sk->linkKnown( $redirectTitle, $redirectText ) ) . |
408 | 408 | "</span>"; |
409 | 409 | } |
410 | 410 | |
411 | 411 | $section = ''; |
412 | 412 | |
413 | 413 | |
414 | | - if (!is_null($sectionTitle)) { |
415 | | - if ($sectionText == '') |
| 414 | + if ( !is_null( $sectionTitle ) ) { |
| 415 | + if ( $sectionText == '' ) |
416 | 416 | $sectionText = null; |
417 | 417 | |
418 | 418 | $section = "<span class='searchalttitle'>" . |
419 | | - wfMsg('search-section', $this->sk->linkKnown($sectionTitle, $sectionText)) . |
| 419 | + wfMsg( 'search-section', $this->sk->linkKnown( $sectionTitle, $sectionText ) ) . |
420 | 420 | "</span>"; |
421 | 421 | } |
422 | 422 | |
423 | 423 | // format text extract |
424 | | - $extract = "<div class='searchresult'>" . $result->getTextSnippet($fieldSets) . "</div>"; |
| 424 | + $extract = "<div class='searchresult'>" . $result->getTextSnippet( $fieldSets ) . "</div>"; |
425 | 425 | |
426 | 426 | // format score |
427 | | - if (is_null($result->getScore())) { |
| 427 | + if ( is_null( $result->getScore() ) ) { |
428 | 428 | // Search engine doesn't report scoring info |
429 | 429 | $score = ''; |
430 | 430 | } else { |
431 | | - $percent = sprintf('%2.1f', $result->getScore() * 100); |
432 | | - $score = wfMsg('search-result-score', $wgLang->formatNum($percent)) . ' - '; |
| 431 | + $percent = sprintf( '%2.1f', $result->getScore() * 100 ); |
| 432 | + $score = wfMsg( 'search-result-score', $wgLang->formatNum( $percent ) ) . ' - '; |
433 | 433 | } |
434 | 434 | |
435 | 435 | // format description |
436 | 436 | $byteSize = $result->getByteSize(); |
437 | 437 | $wordCount = $result->getWordCount(); |
438 | 438 | $timestamp = $result->getTimestamp(); |
439 | | - $size = wfMsgExt('search-result-size', array('parsemag', 'escape'), $this->sk->formatSize($byteSize), $wgLang->formatNum($wordCount)); |
| 439 | + $size = wfMsgExt( 'search-result-size', array( 'parsemag', 'escape' ), $this->sk->formatSize( $byteSize ), $wgLang->formatNum( $wordCount ) ); |
440 | 440 | |
441 | | - if ($t->getNamespace() == NS_CATEGORY) { |
442 | | - $cat = Category::newFromTitle($t); |
443 | | - $size = wfMsgExt('search-result-category-size', array('parsemag', 'escape'), $wgLang->formatNum($cat->getPageCount()), $wgLang->formatNum($cat->getSubcatCount()), $wgLang->formatNum($cat->getFileCount())); |
| 441 | + if ( $t->getNamespace() == NS_CATEGORY ) { |
| 442 | + $cat = Category::newFromTitle( $t ); |
| 443 | + $size = wfMsgExt( 'search-result-category-size', array( 'parsemag', 'escape' ), $wgLang->formatNum( $cat->getPageCount() ), $wgLang->formatNum( $cat->getSubcatCount() ), $wgLang->formatNum( $cat->getFileCount() ) ); |
444 | 444 | } |
445 | 445 | |
446 | | - $date = $wgLang->timeanddate($timestamp); |
| 446 | + $date = $wgLang->timeanddate( $timestamp ); |
447 | 447 | |
448 | 448 | // link to related articles if supported |
449 | 449 | $related = ''; |
450 | | - if ($result->hasRelated()) { |
451 | | - $st = SpecialPage::getTitleFor('SolrSearch'); |
452 | | - $stParams = array('solrsearch' => wfMsgForContent('searchrelated') . ':' . $t->getPrefixedText()); |
453 | | - $related = ' -- ' . $sk->linkKnown($st, wfMsg('search-relatedarticle'), array(), $stParams); |
| 450 | + if ( $result->hasRelated() ) { |
| 451 | + $st = SpecialPage::getTitleFor( 'SolrSearch' ); |
| 452 | + $stParams = array( 'solrsearch' => wfMsgForContent( 'searchrelated' ) . ':' . $t->getPrefixedText() ); |
| 453 | + $related = ' -- ' . $sk->linkKnown( $st, wfMsg( 'search-relatedarticle' ), array(), $stParams ); |
454 | 454 | } |
455 | 455 | |
456 | 456 | // Include a thumbnail for media files... |
457 | 457 | // WE HAVE NEVER TESTED THIS HERE!!! |
458 | | - if ($t->getNamespace() == NS_FILE) { |
459 | | - $img = wfFindFile($t); |
460 | | - if ($img) { |
461 | | - $thumb = $img->transform(array('width' => 120, 'height' => 120)); |
462 | | - if ($thumb) { |
463 | | - $desc = wfMsg('parentheses', $img->getShortDesc()); |
464 | | - wfProfileOut(__METHOD__); |
| 458 | + if ( $t->getNamespace() == NS_FILE ) { |
| 459 | + $img = wfFindFile( $t ); |
| 460 | + if ( $img ) { |
| 461 | + $thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) ); |
| 462 | + if ( $thumb ) { |
| 463 | + $desc = wfMsg( 'parentheses', $img->getShortDesc() ); |
| 464 | + wfProfileOut( __METHOD__ ); |
465 | 465 | // Float doesn't seem to interact well with the bullets. |
466 | 466 | // Table messes up vertical alignment of the bullets. |
467 | 467 | // Bullets are therefore disabled (didn't look great anyway). |
— | — | @@ -468,7 +468,7 @@ |
469 | 469 | '<table class="searchResultImage">' . |
470 | 470 | '<tr>' . |
471 | 471 | '<td width="120" align="center" valign="top">' . |
472 | | - $thumb->toHtml(array('desc-link' => true)) . |
| 472 | + $thumb->toHtml( array( 'desc-link' => true ) ) . |
473 | 473 | '</td>' . |
474 | 474 | '<td valign="top">' . |
475 | 475 | $link . |
— | — | @@ -482,66 +482,66 @@ |
483 | 483 | } |
484 | 484 | } |
485 | 485 | |
486 | | - wfProfileOut(__METHOD__); |
| 486 | + wfProfileOut( __METHOD__ ); |
487 | 487 | // HIER kommt die score ausgabe: |
488 | 488 | return "<li><div class='mw-search-result-heading'>{$link} {$redirect} {$section}</div> {$extract}\n" . |
489 | 489 | "<div class='mw-search-result-data'>{$score}{$date}{$related}</div>" . |
490 | 490 | "</li>\n"; |
491 | 491 | } |
492 | 492 | |
493 | | - protected function formHeader($fieldSet, $resultsShown, $totalNum) { |
| 493 | + protected function formHeader( $fieldSet, $resultsShown, $totalNum ) { |
494 | 494 | global $wgLang; |
495 | 495 | |
496 | | - $out = Xml::openElement('div', array('class' => 'mw-search-formheader')); |
| 496 | + $out = Xml::openElement( 'div', array( 'class' => 'mw-search-formheader' ) ); |
497 | 497 | |
498 | 498 | // Results-info |
499 | | - if ($resultsShown > 0) { |
500 | | - if ($totalNum > 0) { |
501 | | - $top = wfMsgExt('showingresultsheader', array('parseinline'), $wgLang->formatNum($this->offset + 1), $wgLang->formatNum($this->offset + $resultsShown), $wgLang->formatNum($totalNum), $wgLang->formatNum($resultsShown) |
| 499 | + if ( $resultsShown > 0 ) { |
| 500 | + if ( $totalNum > 0 ) { |
| 501 | + $top = wfMsgExt( 'showingresultsheader', array( 'parseinline' ), $wgLang->formatNum( $this->offset + 1 ), $wgLang->formatNum( $this->offset + $resultsShown ), $wgLang->formatNum( $totalNum ), $wgLang->formatNum( $resultsShown ) |
502 | 502 | ); |
503 | | - } elseif ($resultsShown >= $this->limit) { |
504 | | - $top = wfShowingResults($this->offset, $this->limit); |
| 503 | + } elseif ( $resultsShown >= $this->limit ) { |
| 504 | + $top = wfShowingResults( $this->offset, $this->limit ); |
505 | 505 | } else { |
506 | | - $top = wfShowingResultsNum($this->offset, $this->limit, $resultsShown); |
| 506 | + $top = wfShowingResultsNum( $this->offset, $this->limit, $resultsShown ); |
507 | 507 | } |
508 | | - $out .= Xml::tags('div', array('class' => 'results-info'), Xml::tags('ul', null, Xml::tags('li', null, $top))); |
| 508 | + $out .= Xml::tags( 'div', array( 'class' => 'results-info' ), Xml::tags( 'ul', null, Xml::tags( 'li', null, $top ) ) ); |
509 | 509 | } |
510 | 510 | |
511 | | - $out .= Xml::element('div', array('style' => 'clear:both'), '', false); |
512 | | - $out .= Xml::closeElement('div'); |
| 511 | + $out .= Xml::element( 'div', array( 'style' => 'clear:both' ), '', false ); |
| 512 | + $out .= Xml::closeElement( 'div' ); |
513 | 513 | |
514 | 514 | return $out; |
515 | 515 | } |
516 | 516 | |
517 | | - protected function shortDialog($fieldSet) { |
518 | | - $searchTitle = SpecialPage::getTitleFor('SolrSearch'); |
| 517 | + protected function shortDialog( $fieldSet ) { |
| 518 | + $searchTitle = SpecialPage::getTitleFor( 'SolrSearch' ); |
519 | 519 | |
520 | 520 | |
521 | | - if ($fieldSet->getName() != 'search') { |
522 | | - $out = Html::hidden('title', $searchTitle->getPrefixedText() . '/' . $fieldSet->getName()) . "\n"; |
| 521 | + if ( $fieldSet->getName() != 'search' ) { |
| 522 | + $out = Html::hidden( 'title', $searchTitle->getPrefixedText() . '/' . $fieldSet->getName() ) . "\n"; |
523 | 523 | } else { |
524 | | - $out = Html::hidden('title', $searchTitle->getPrefixedText()) . "\n"; |
| 524 | + $out = Html::hidden( 'title', $searchTitle->getPrefixedText() ) . "\n"; |
525 | 525 | } |
526 | 526 | // Term box |
527 | 527 | |
528 | 528 | $lable = $fieldSet->getLable(); |
529 | 529 | $out .= '<table>'; |
530 | 530 | |
531 | | - foreach ($fieldSet->getFields() as $key => $value) { |
| 531 | + foreach ( $fieldSet->getFields() as $key => $value ) { |
532 | 532 | $out .= '<tr>'; |
533 | | - if (isset($lable[$key])) { |
| 533 | + if ( isset( $lable[$key] ) ) { |
534 | 534 | $out .= '<th>' . $lable[$key] . '</th>'; |
535 | 535 | } |
536 | 536 | $out .= '<td>'; |
537 | | - $out .= Html::input($key, $value, $key, array( |
| 537 | + $out .= Html::input( $key, $value, $key, array( |
538 | 538 | 'id' => $key, |
539 | 539 | 'size' => '50', |
540 | 540 | 'autofocus' |
541 | | - )) . "\n"; |
| 541 | + ) ) . "\n"; |
542 | 542 | $out .= '</td></tr>'; |
543 | 543 | } |
544 | 544 | $out .= '<table>'; |
545 | | - $out .= Xml::submitButton(wfMsg('searchbutton')) . "\n"; |
| 545 | + $out .= Xml::submitButton( wfMsg( 'searchbutton' ) ) . "\n"; |
546 | 546 | return $out . $this->didYouMeanHtml; |
547 | 547 | } |
548 | 548 | |
Index: trunk/extensions/SolrStore/SolrConnectorStore.php |
— | — | @@ -9,7 +9,7 @@ |
10 | 10 | |
11 | 11 | /** |
12 | 12 | * TODO: Insert class description |
13 | | - * |
| 13 | + * |
14 | 14 | * @ingroup SolrStore |
15 | 15 | */ |
16 | 16 | class SolrConnectorStore extends SMWStore { |
— | — | @@ -28,14 +28,14 @@ |
29 | 29 | static function &getBaseStore() { |
30 | 30 | global $wgscBaseStore; |
31 | 31 | |
32 | | - if (self::$smBaseStore === null) { |
| 32 | + if ( self::$smBaseStore === null ) { |
33 | 33 | self::$smBaseStore = new $wgscBaseStore(); |
34 | 34 | } |
35 | 35 | |
36 | 36 | return self::$smBaseStore; |
37 | 37 | } |
38 | 38 | |
39 | | -///// Reading methods ///// |
| 39 | +//// / Reading methods ///// |
40 | 40 | |
41 | 41 | /** |
42 | 42 | * Retrieve all data stored about the given subject and return it as a |
— | — | @@ -49,8 +49,8 @@ |
50 | 50 | * data than requested when a filter is used. Filtering just ensures |
51 | 51 | * that only necessary requests are made, i.e. it improves performance. |
52 | 52 | */ |
53 | | - public function getSemanticData(SMWDIWikiPage $subject, $filter = false) { |
54 | | - return self::getBaseStore()->getSemanticData($subject, $filter); |
| 53 | + public function getSemanticData( SMWDIWikiPage $subject, $filter = false ) { |
| 54 | + return self::getBaseStore()->getSemanticData( $subject, $filter ); |
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
— | — | @@ -66,8 +66,8 @@ |
67 | 67 | * |
68 | 68 | * @return array of SMWDataItem |
69 | 69 | */ |
70 | | - public function getPropertyValues($subject, SMWDIProperty $property, $requestoptions = null) { |
71 | | - return self::getBaseStore()->getPropertyValues($subject, $property, $requestoptions); |
| 70 | + public function getPropertyValues( $subject, SMWDIProperty $property, $requestoptions = null ) { |
| 71 | + return self::getBaseStore()->getPropertyValues( $subject, $property, $requestoptions ); |
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
— | — | @@ -75,16 +75,16 @@ |
76 | 76 | * property. The result is an array of SMWDIWikiPage objects. If null |
77 | 77 | * is given as a value, all subjects having that property are returned. |
78 | 78 | */ |
79 | | - public function getPropertySubjects(SMWDIProperty $property, $value, $requestoptions = null) { |
80 | | - return self::getBaseStore()->getPropertySubjects($property, $value, $requestoptions); |
| 79 | + public function getPropertySubjects( SMWDIProperty $property, $value, $requestoptions = null ) { |
| 80 | + return self::getBaseStore()->getPropertySubjects( $property, $value, $requestoptions ); |
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
84 | 84 | * Get an array of all subjects that have some value for the given |
85 | 85 | * property. The result is an array of SMWDIWikiPage objects. |
86 | 86 | */ |
87 | | - public function getAllPropertySubjects(SMWDIProperty $property, $requestoptions = null) { |
88 | | - return self::getBaseStore()->getAllPropertySubjects($property, $requestoptions); |
| 87 | + public function getAllPropertySubjects( SMWDIProperty $property, $requestoptions = null ) { |
| 88 | + return self::getBaseStore()->getAllPropertySubjects( $property, $requestoptions ); |
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
— | — | @@ -94,8 +94,8 @@ |
95 | 95 | * @param $subject SMWDIWikiPage denoting the subject |
96 | 96 | * @param $requestoptions SMWRequestOptions optionally defining further options |
97 | 97 | */ |
98 | | - public function getProperties(SMWDIWikiPage $subject, $requestoptions = null) { |
99 | | - return self::getBaseStore()->getProperties($subject, $requestoptions); |
| 98 | + public function getProperties( SMWDIWikiPage $subject, $requestoptions = null ) { |
| 99 | + return self::getBaseStore()->getProperties( $subject, $requestoptions ); |
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
— | — | @@ -105,11 +105,11 @@ |
106 | 106 | * @note In some stores, this function might be implemented partially |
107 | 107 | * so that only values of type Page (_wpg) are supported. |
108 | 108 | */ |
109 | | - public function getInProperties(SMWDataItem $object, $requestoptions = null) { |
110 | | - return self::getBaseStore()->getInProperties($object, $requestoptions); |
| 109 | + public function getInProperties( SMWDataItem $object, $requestoptions = null ) { |
| 110 | + return self::getBaseStore()->getInProperties( $object, $requestoptions ); |
111 | 111 | } |
112 | 112 | |
113 | | -///// Writing methods ///// |
| 113 | +//// / Writing methods ///// |
114 | 114 | |
115 | 115 | /** |
116 | 116 | * Delete all semantic properties that the given subject has. This |
— | — | @@ -119,12 +119,12 @@ |
120 | 120 | * |
121 | 121 | * @param Title $subject |
122 | 122 | */ |
123 | | - public function deleteSubject(Title $subject) { |
| 123 | + public function deleteSubject( Title $subject ) { |
124 | 124 | global $wgSolrTalker; |
125 | | - //TODO: Update Solr to reflect the deleting of semantic properties |
| 125 | + // TODO: Update Solr to reflect the deleting of semantic properties |
126 | 126 | |
127 | | - $wgSolrTalker->deleteDocId($subject); |
128 | | - return self::getBaseStore()->deleteSubject($subject); |
| 127 | + $wgSolrTalker->deleteDocId( $subject ); |
| 128 | + return self::getBaseStore()->deleteSubject( $subject ); |
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
— | — | @@ -134,10 +134,10 @@ |
135 | 135 | * |
136 | 136 | * @param SMWSemanticData $data |
137 | 137 | */ |
138 | | - public function doDataUpdate(SMWSemanticData $data) { |
| 138 | + public function doDataUpdate( SMWSemanticData $data ) { |
139 | 139 | global $wgSolrTalker; |
140 | | - $wgSolrTalker->parseSemanticData($data); |
141 | | - return self::getBaseStore()->doDataUpdate($data); |
| 140 | + $wgSolrTalker->parseSemanticData( $data ); |
| 141 | + return self::getBaseStore()->doDataUpdate( $data ); |
142 | 142 | } |
143 | 143 | |
144 | 144 | /** |
— | — | @@ -150,13 +150,13 @@ |
151 | 151 | * redirect, if any, is given by $redirid. If no new page was created, |
152 | 152 | * $redirid will be 0. |
153 | 153 | */ |
154 | | - public function changeTitle(Title $oldtitle, Title $newtitle, $pageid, $redirid = 0) { |
155 | | - |
156 | | - //TODO: Update Solr to reflect a renaming of some article |
157 | | - return self::getBaseStore()->changeTitle($oldtitle, $newtitle, $pageid, $redirid); |
| 154 | + public function changeTitle( Title $oldtitle, Title $newtitle, $pageid, $redirid = 0 ) { |
| 155 | + |
| 156 | + // TODO: Update Solr to reflect a renaming of some article |
| 157 | + return self::getBaseStore()->changeTitle( $oldtitle, $newtitle, $pageid, $redirid ); |
158 | 158 | } |
159 | 159 | |
160 | | -///// Query answering ///// |
| 160 | +//// / Query answering ///// |
161 | 161 | |
162 | 162 | /** |
163 | 163 | * Execute the provided query and return the result as an |
— | — | @@ -169,56 +169,56 @@ |
170 | 170 | * |
171 | 171 | * @return SMWQueryResult |
172 | 172 | */ |
173 | | - public function getQueryResult(SMWQuery $query) { |
174 | | - //IF YOU SEE THIS HERE PLEASE IGNORE IT! |
175 | | - //Our first aproche was it to create new SMWStore for Querying Data |
176 | | - //but we had big Problems recreating and parsing the SMW Query Syntax |
177 | | - //that we just Stoped at this Point here. Maybe we will finish it someday |
| 173 | + public function getQueryResult( SMWQuery $query ) { |
| 174 | + // IF YOU SEE THIS HERE PLEASE IGNORE IT! |
| 175 | + // Our first aproche was it to create new SMWStore for Querying Data |
| 176 | + // but we had big Problems recreating and parsing the SMW Query Syntax |
| 177 | + // that we just Stoped at this Point here. Maybe we will finish it someday |
178 | 178 | $wgSolrTalker = new SolrTalker(); |
179 | | - if (property_exists($query, 'params') && |
180 | | - array_key_exists('source', $query->params) && |
181 | | - $query->params['source'] == 'solr') { |
| 179 | + if ( property_exists( $query, 'params' ) && |
| 180 | + array_key_exists( 'source', $query->params ) && |
| 181 | + $query->params['source'] == 'solr' ) { |
182 | 182 | |
183 | 183 | $results = array(); |
184 | 184 | $dbkey = ''; |
185 | 185 | $namespace = 0; |
186 | 186 | $interwiki = ''; |
187 | 187 | |
188 | | - echo("SOLR query: {$query->getQueryString()}\n"); |
| 188 | + echo( "SOLR query: {$query->getQueryString()}\n" ); |
189 | 189 | |
190 | | - echo("Search is Powered by Solr!"); |
191 | | - echo $queryStr = urldecode($wgSolrTalker->parseSolrQuery($query->getQueryString())); |
192 | | - |
193 | | - |
194 | | - //Get Sort Parameters and add them to the QueryString |
195 | | - if ($query->sort) { |
196 | | - //TODO: Der Inhalt von Sort muss genau der Name eines der Felder von Solr sein |
| 190 | + echo( "Search is Powered by Solr!" ); |
| 191 | + echo $queryStr = urldecode( $wgSolrTalker->parseSolrQuery( $query->getQueryString() ) ); |
| 192 | + |
| 193 | + |
| 194 | + // Get Sort Parameters and add them to the QueryString |
| 195 | + if ( $query->sort ) { |
| 196 | + // TODO: Der Inhalt von Sort muss genau der Name eines der Felder von Solr sein |
197 | 197 | // um danach Sortieren zu können. Deshalb Wird eine Liste alle Solr Felder |
198 | 198 | // Benötigt um Festzustellen welches Feld gemeint ist bzw. welche _XYZ Endung |
199 | 199 | // an dem Ende des Feldes angehängt wurde. |
200 | | - // |
| 200 | + // |
201 | 201 | |
202 | 202 | |
203 | | - $sort = $wgSolrTalker->findField($query->params['sort'], $query->params['order']); |
204 | | - $queryStr .= '&sort%3D' . $sort . '+' . trim($query->params['order']); |
| 203 | + $sort = $wgSolrTalker->findField( $query->params['sort'], $query->params['order'] ); |
| 204 | + $queryStr .= '&sort%3D' . $sort . '+' . trim( $query->params['order'] ); |
205 | 205 | // $queryStr = $queryStr . '&sort=' . trim($sort . '+' . trim($query->params['order'])); |
206 | | - //TODO: Mehrer Sort parameter auslesen wenn sie vorhanden sind. |
207 | | - } |
| 206 | + // TODO: Mehrer Sort parameter auslesen wenn sie vorhanden sind. |
| 207 | + } |
208 | 208 | // else { |
209 | 209 | // $queryStr = $queryStr . '&sort=pagetitle'; |
210 | 210 | // } |
211 | | - |
212 | | - //TODO: Prüfen wieso nur 1 Ergebniss ausgegeben wird |
213 | | - echo 'Query Limit:'.$query->getLimit(); |
214 | 211 | |
215 | | - echo ("SEARCHRESULT: " . $xml = $wgSolrTalker->solrQuery($queryStr, $query->getOffset(), $query->getLimit())); |
216 | | - echo("<br/>"); |
217 | | - //TODO: Move this Code to parseSolrResult |
| 212 | + // TODO: Prüfen wieso nur 1 Ergebniss ausgegeben wird |
| 213 | + echo 'Query Limit:' . $query->getLimit(); |
| 214 | + |
| 215 | + echo ( "SEARCHRESULT: " . $xml = $wgSolrTalker->solrQuery( $queryStr, $query->getOffset(), $query->getLimit() ) ); |
| 216 | + echo( "<br/>" ); |
| 217 | + // TODO: Move this Code to parseSolrResult |
218 | 218 | $numFound = $xml->result['numFound']; |
219 | 219 | // print_r('1: ' . $xml->{"result"}); |
220 | | - foreach ($xml->result->doc as $doc) { |
221 | | - foreach ($doc->str as $field) { |
222 | | - switch ($field['name']) { |
| 220 | + foreach ( $xml->result->doc as $doc ) { |
| 221 | + foreach ( $doc->str as $field ) { |
| 222 | + switch ( $field['name'] ) { |
223 | 223 | case 'dbkey': |
224 | 224 | $dbkey = $field; |
225 | 225 | break; |
— | — | @@ -230,9 +230,9 @@ |
231 | 231 | break; |
232 | 232 | } |
233 | 233 | } |
234 | | - // Multivalue Felder |
235 | | - foreach ($doc->arr as $field) { |
236 | | - switch ($field['name']) { |
| 234 | + // Multivalue Felder |
| 235 | + foreach ( $doc->arr as $field ) { |
| 236 | + switch ( $field['name'] ) { |
237 | 237 | case 'dbkey': |
238 | 238 | $dbkey = $field; |
239 | 239 | break; |
— | — | @@ -243,29 +243,29 @@ |
244 | 244 | $namespace = $field; |
245 | 245 | break; |
246 | 246 | } |
247 | | - foreach ($field->str as $value) { |
| 247 | + foreach ( $field->str as $value ) { |
248 | 248 | $value; |
249 | 249 | } |
250 | 250 | } |
251 | | - $results[] = new SMWDIWikiPage($dbkey, $namespace, $interwiki); |
| 251 | + $results[] = new SMWDIWikiPage( $dbkey, $namespace, $interwiki ); |
252 | 252 | } |
253 | | - |
| 253 | + |
254 | 254 | // Do we have more Results ? |
255 | 255 | $more = false; |
256 | | - //TODO: Does this Work ? |
257 | | - echo 'Number of Records: '.$numFound; |
258 | | - if ($numFound > 10) { |
| 256 | + // TODO: Does this Work ? |
| 257 | + echo 'Number of Records: ' . $numFound; |
| 258 | + if ( $numFound > 10 ) { |
259 | 259 | $more = true; |
260 | 260 | } |
261 | | - |
262 | | - //return new SMWQueryResult($printRequests, $query, $results, $store); |
263 | | - return new SMWQueryResult($query->getDescription()->getPrintrequests(), $query, $results, $this, $more); |
| 261 | + |
| 262 | + // return new SMWQueryResult($printRequests, $query, $results, $store); |
| 263 | + return new SMWQueryResult( $query->getDescription()->getPrintrequests(), $query, $results, $this, $more ); |
264 | 264 | } else { |
265 | | - return self::getBaseStore()->getQueryResult($query); |
| 265 | + return self::getBaseStore()->getQueryResult( $query ); |
266 | 266 | } |
267 | 267 | } |
268 | 268 | |
269 | | -///// Special page functions ///// |
| 269 | +//// / Special page functions ///// |
270 | 270 | |
271 | 271 | /** |
272 | 272 | * Return all properties that have been used on pages in the wiki. The |
— | — | @@ -277,8 +277,8 @@ |
278 | 278 | * |
279 | 279 | * @return array |
280 | 280 | */ |
281 | | - public function getPropertiesSpecial($requestoptions = null) { |
282 | | - return self::getBaseStore()->getPropertiesSpecial($requestoptions); |
| 281 | + public function getPropertiesSpecial( $requestoptions = null ) { |
| 282 | + return self::getBaseStore()->getPropertiesSpecial( $requestoptions ); |
283 | 283 | } |
284 | 284 | |
285 | 285 | /** |
— | — | @@ -291,8 +291,8 @@ |
292 | 292 | * |
293 | 293 | * @return array of SMWDIProperty |
294 | 294 | */ |
295 | | - public function getUnusedPropertiesSpecial($requestoptions = null) { |
296 | | - return self::getBaseStore()->getUnusedPropertiesSpecial($requestoptions); |
| 295 | + public function getUnusedPropertiesSpecial( $requestoptions = null ) { |
| 296 | + return self::getBaseStore()->getUnusedPropertiesSpecial( $requestoptions ); |
297 | 297 | } |
298 | 298 | |
299 | 299 | /** |
— | — | @@ -305,8 +305,8 @@ |
306 | 306 | * |
307 | 307 | * @return array of array( SMWDIProperty, int ) |
308 | 308 | */ |
309 | | - public function getWantedPropertiesSpecial($requestoptions = null) { |
310 | | - return self::getBaseStore()->getWantedPropertiesSpecial($requestoptions); |
| 309 | + public function getWantedPropertiesSpecial( $requestoptions = null ) { |
| 310 | + return self::getBaseStore()->getWantedPropertiesSpecial( $requestoptions ); |
311 | 311 | } |
312 | 312 | |
313 | 313 | /** |
— | — | @@ -322,7 +322,7 @@ |
323 | 323 | return self::getBaseStore()->getStatistics(); |
324 | 324 | } |
325 | 325 | |
326 | | -///// Setup store ///// |
| 326 | +//// / Setup store ///// |
327 | 327 | |
328 | 328 | /** |
329 | 329 | * Setup all storage structures properly for using the store. This |
— | — | @@ -341,11 +341,11 @@ |
342 | 342 | * |
343 | 343 | * @param boolean $verbose |
344 | 344 | */ |
345 | | - public function setup($verbose = true) { |
| 345 | + public function setup( $verbose = true ) { |
346 | 346 | |
347 | | - //TODO: Setup data structures on the the Solr server, if necessary |
| 347 | + // TODO: Setup data structures on the the Solr server, if necessary |
348 | 348 | |
349 | | - return self::getBaseStore()->setup($verbose); |
| 349 | + return self::getBaseStore()->setup( $verbose ); |
350 | 350 | } |
351 | 351 | |
352 | 352 | /** |
— | — | @@ -354,12 +354,12 @@ |
355 | 355 | * |
356 | 356 | * @param boolean $verbose |
357 | 357 | */ |
358 | | - public function drop($verbose = true) { |
| 358 | + public function drop( $verbose = true ) { |
359 | 359 | global $wgSolrTalker; |
360 | 360 | $wgSolrTalker->deleteAllDocs(); |
361 | | - //Drop all data from Solr |
| 361 | + // Drop all data from Solr |
362 | 362 | |
363 | | - return self::getBaseStore()->drop($verbose); |
| 363 | + return self::getBaseStore()->drop( $verbose ); |
364 | 364 | } |
365 | 365 | |
366 | 366 | /** |
— | — | @@ -389,11 +389,11 @@ |
390 | 390 | * |
391 | 391 | * @return decimal between 0 and 1 to indicate the overall progress of the refreshing |
392 | 392 | */ |
393 | | - public function refreshData(&$index, $count, $namespaces = false, $usejobs = true) { |
| 393 | + public function refreshData( &$index, $count, $namespaces = false, $usejobs = true ) { |
394 | 394 | |
395 | | - //TODO: Do we need to do something here for Solr? Can we do something? |
| 395 | + // TODO: Do we need to do something here for Solr? Can we do something? |
396 | 396 | |
397 | | - return self::getBaseStore()->refreshData($index, $count, $namespaces, $usejobs); |
| 397 | + return self::getBaseStore()->refreshData( $index, $count, $namespaces, $usejobs ); |
398 | 398 | } |
399 | 399 | |
400 | 400 | } |