Index: trunk/extensions/SolrStore/SolrTalker.php |
— | — | @@ -14,12 +14,12 @@ |
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 | | - * Get the Schema from SOLR as XML |
23 | | - * This Includes all Dynamic Fields |
| 22 | + * Get the Schema from SOLR as XML |
| 23 | + * This includes all dynamic fields |
24 | 24 | * |
25 | 25 | * @return type $xml schema |
26 | 26 | */ |
— | — | @@ -37,7 +37,7 @@ |
38 | 38 | } |
39 | 39 | |
40 | 40 | public function encodeSolr( $query ) { |
41 | | - // Using the urlencode from php doenst work!?, so we need to do it our self |
| 41 | + // Using the urlencode from PHP doesn't work!? So we need to do it ourself |
42 | 42 | $query = str_replace( '"', '%22', trim( $query ) ); |
43 | 43 | $query = str_replace( ' ', '+', $query ); |
44 | 44 | $query = str_replace( 'ü', '%FC', $query ); |
— | — | @@ -53,14 +53,14 @@ |
54 | 54 | * Perform a SolrSearch |
55 | 55 | * |
56 | 56 | * @global type $wgSolrUrl |
57 | | - * @param type $query - Search Term |
58 | | - * @param type $start - Offset |
59 | | - * @param type $end - Limit |
| 57 | + * @param $query String: search term |
| 58 | + * @param $start Integer: offset |
| 59 | + * @param $end Integer: limit |
60 | 60 | * @return type $xml - Solr Result as XML |
61 | | - * |
62 | 61 | */ |
63 | 62 | public function solrQuery( $query, $start, $end, $highlight = false, $score = false ) { |
64 | 63 | global $wgSolrUrl; |
| 64 | + |
65 | 65 | $query = trim( $query ); |
66 | 66 | if ( empty( $query ) ) { |
67 | 67 | $query = '*'; |
— | — | @@ -72,6 +72,7 @@ |
73 | 73 | if ( $score ) { |
74 | 74 | $url .= '&fl=*%2Cscore'; |
75 | 75 | } |
| 76 | + |
76 | 77 | return $this->solrSend( $url ); |
77 | 78 | } |
78 | 79 | |
— | — | @@ -79,13 +80,13 @@ |
80 | 81 | * Find the real name of the Field in the SOlr schema |
81 | 82 | * |
82 | 83 | * @param type $searchField |
83 | | - * @param type $sort = ASC or DESC |
| 84 | + * @param $sort String: ASC or DESC |
84 | 85 | * @return type Name of the Field you are searching for |
85 | 86 | */ |
86 | 87 | public function findField( $searchField, $sort = 'ASC' ) { |
87 | 88 | $xml = $this->getSchema(); |
88 | 89 | // $searchField = trim($searchField); |
89 | | - $searchField = str_replace( ' ', '_', trim( $searchField ) ); // Trim and Replace all Spaces with underscore for better matching |
| 90 | + $searchField = str_replace( ' ', '_', trim( $searchField ) ); // Trim and replace all spaces with underscore for better matching |
90 | 91 | $result = false; |
91 | 92 | $stop = false; |
92 | 93 | |
— | — | @@ -94,17 +95,17 @@ |
95 | 96 | if ( $item['name'] == 'fields' ) { |
96 | 97 | foreach ( $item->lst as $field ) { |
97 | 98 | 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 |
| 99 | + $dynamicBase = substr( $field->str[2], 1 ); // Get the dynamic base of the field eg. "*_dtmax" |
| 100 | + $newField = str_replace( $dynamicBase, '', $field['name'] ); // Get the field name without the dynamicbase |
| 101 | + if ( strcasecmp( str_replace( ' ', '_', $newField ), $searchField ) == 0 ) { // Replace all spaces with underscore for better matching |
101 | 102 | if ( stripos( $dynamicBase, 'max' ) && stripos( $sort, 'desc' ) ) { |
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 | + // For descending sorting use the MaX value field |
| 104 | + continue 2; // we got the right field, stop it! |
| 105 | + } elseif ( stripos( $dynamicBase, 'min' ) && stripos( $sort, 'asc' ) ) { |
| 106 | + // For ascending sorting use the MIN value field |
| 107 | + continue 2; // we got the right field, stop it! |
107 | 108 | } |
108 | | - } else if ( strcasecmp( str_replace( ' ', '_', $field['name'] ), $searchField ) == 0 ) { // Replace all Spaces with underscore for better matching |
| 109 | + } elseif ( strcasecmp( str_replace( ' ', '_', $field['name'] ), $searchField ) == 0 ) { // Replace all spaces with underscore for better matching |
109 | 110 | $result = trim( $searchField ); |
110 | 111 | } |
111 | 112 | } else { |
— | — | @@ -119,7 +120,7 @@ |
120 | 121 | } |
121 | 122 | |
122 | 123 | /** |
123 | | - * Check the Query for existing fields |
| 124 | + * Check the query for existing fields |
124 | 125 | * |
125 | 126 | * @param type $queryStr - Wiki QueryString |
126 | 127 | * @return type $queryStr - Solr QueryString |
— | — | @@ -127,12 +128,12 @@ |
128 | 129 | public function queryChecker( $queryStr ) { |
129 | 130 | $queryStr = str_replace( '=', ':', $queryStr ); // Now you can use = insted : for querying Fields |
130 | 131 | if ( strpos( $queryStr, ':' ) !== false ) { |
131 | | - $queryParts = explode( " ", $queryStr ); // Split on Spaces and Search for Fields |
| 132 | + $queryParts = explode( ' ', $queryStr ); // Split on spaces and Search for Fields |
132 | 133 | $queryStr = ''; |
133 | 134 | foreach ( $queryParts as $value ) { |
134 | 135 | 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 |
| 136 | + $parts = explode( ':', $value ); // Split the query part in key (parts[0]) and value (parts[1]) |
| 137 | + $solrField = $this->findField( $parts[0] ); // Search for a Solr field for the key |
137 | 138 | if ( $solrField ) { |
138 | 139 | $queryStr = $queryStr . ' ' . $solrField . ':' . $parts[1]; |
139 | 140 | } else { |
— | — | @@ -148,7 +149,7 @@ |
149 | 150 | } |
150 | 151 | |
151 | 152 | /** |
152 | | - * Transform a Wiki Query to a Solr Query |
| 153 | + * Transform a wiki query to a Solr query |
153 | 154 | * TODO: Do more Wiki2Solr transformation |
154 | 155 | * |
155 | 156 | * @param type $queryStr - Wiki QueryString |
— | — | @@ -156,15 +157,15 @@ |
157 | 158 | */ |
158 | 159 | public function parseSolrQuery( $queryStr ) { |
159 | 160 | // TODO: Parse the QueryString to make it work in Solr |
160 | | - $queryParts = explode( "[[", $queryStr ); |
| 161 | + $queryParts = explode( '[[', $queryStr ); |
161 | 162 | |
162 | 163 | // Clean the queryStr |
163 | 164 | $queryStr = ''; |
164 | 165 | foreach ( $queryParts as $part ) { |
165 | 166 | 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 |
| 167 | + $parts = explode( '::', $part ); // Split the query part in key (parts[0]) and value (parts[1]) |
| 168 | + $parts[0] = $this->findField( $parts[0] ); // Search for a Solr field for the key |
| 169 | + $queryStr = $queryStr . ' ' . $parts[0] . ':' . $parts[1]; // Build query string |
169 | 170 | } elseif ( stripos( $part, ':' ) ) { |
170 | 171 | $queryStr = $queryStr . ' category' . substr( $part, stripos( $part, ':' ) ); |
171 | 172 | } else { |
— | — | @@ -196,7 +197,7 @@ |
197 | 198 | } |
198 | 199 | |
199 | 200 | /** |
200 | | - * Private Function for interactinig with Solr. |
| 201 | + * Private function for interacting with Solr. |
201 | 202 | * |
202 | 203 | * @param type $url |
203 | 204 | * @param type $xmlcontent |
— | — | @@ -230,15 +231,12 @@ |
231 | 232 | |
232 | 233 | // if the request was successful |
233 | 234 | if ( $httpCode == 200 ) { |
234 | | - |
235 | 235 | try { |
236 | 236 | $xml = new SimpleXMLElement( $data ); |
237 | 237 | } catch ( Exception $exc ) { |
238 | 238 | throw new MWException( $exc->getMessage() ); |
239 | 239 | } |
240 | | - |
241 | 240 | } else { // some error occurred |
242 | | - |
243 | 241 | // have to scrape the error message from the returned HTML |
244 | 242 | $xml = new DOMDocument; |
245 | 243 | $xml->loadHTML( $data ); |
— | — | @@ -259,8 +257,8 @@ |
260 | 258 | * @param SolrDoc $file |
261 | 259 | */ |
262 | 260 | public function addDoc( SolrDoc $file ) { |
263 | | - $filekopf = "<add><doc>"; |
264 | | - $filefuss = "</doc></add>"; |
| 261 | + $filekopf = '<add><doc>'; |
| 262 | + $filefuss = '</doc></add>'; |
265 | 263 | $xmlcontent = $filekopf . $file->printFields() . $filefuss; |
266 | 264 | return $this->solrAdd( $xmlcontent ); |
267 | 265 | } |
— | — | @@ -271,8 +269,8 @@ |
272 | 270 | * @return type $xml - Response from Solr |
273 | 271 | */ |
274 | 272 | public function deleteDocId( $id ) { |
275 | | - $filekopf = "<delte><id>"; |
276 | | - $filefuss = "</id></delte>"; |
| 273 | + $filekopf = '<delte><id>'; |
| 274 | + $filefuss = '</id></delte>'; |
277 | 275 | $xmlcontent = $filekopf . $id . $filefuss; |
278 | 276 | return $this->solrAdd( $xmlcontent ); |
279 | 277 | } |
— | — | @@ -283,14 +281,14 @@ |
284 | 282 | * @return type $xml - Response from Solr |
285 | 283 | */ |
286 | 284 | public function deleteDocQuery( $query ) { |
287 | | - $filekopf = "<delte><query>"; |
288 | | - $filefuss = "</query></delte>"; |
| 285 | + $filekopf = '<delte><query>'; |
| 286 | + $filefuss = '</query></delte>'; |
289 | 287 | $xmlcontent = $filekopf . $query . $filefuss; |
290 | 288 | return $this->solrAdd( $xmlcontent ); |
291 | 289 | } |
292 | 290 | |
293 | 291 | /** |
294 | | - * DELETE ALL DOCS FROM SOLR INDEX!!! |
| 292 | + * DELETE ALL DOCS FROM SOLR INDEX! |
295 | 293 | * @return type $xml - Response from Solr |
296 | 294 | */ |
297 | 295 | public function deleteAllDocs() { |
— | — | @@ -299,18 +297,19 @@ |
300 | 298 | } |
301 | 299 | |
302 | 300 | /** |
303 | | - * This Function is used for Storing an SMWSemanticData Item in the Solr Index |
| 301 | + * This function is used for storing a SMWSemanticData Item in the Solr |
| 302 | + * Index |
304 | 303 | * |
305 | 304 | * @param SMWSemanticData $data |
306 | 305 | */ |
307 | 306 | public function parseSemanticData( SMWSemanticData $data ) { |
308 | | - $solritem = new SolrDoc (); |
| 307 | + $solritem = new SolrDoc(); |
309 | 308 | |
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() ); |
| 309 | + $solritem->addField( 'pagetitle', $data->getSubject()->getTitle()->getText() ); |
| 310 | + $solritem->addField( 'namespace', $data->getSubject()->getNamespace() ); |
| 311 | + $solritem->addField( 'dbkey', $data->getSubject()->getDBkey() ); |
| 312 | + $solritem->addField( 'interwiki', $data->getSubject()->getInterwiki() ); |
| 313 | + $solritem->addField( 'subobjectname', $data->getSubject()->getSubobjectName() ); |
315 | 314 | |
316 | 315 | foreach ( $data->getProperties() as $property ) { |
317 | 316 | if ( ( $property->getKey() == '_SKEY' ) || ( $property->getKey() == '_REDI' ) ) { |
— | — | @@ -325,71 +324,71 @@ |
326 | 325 | } |
327 | 326 | switch ( $di->getDIType() ) { |
328 | 327 | case 0: |
329 | | -// /// Data item ID that can be used to indicate that no data item class is appropriate |
330 | | -// const TYPE_NOTYPE = 0; |
| 328 | + // /// Data item ID that can be used to indicate that no data item class is appropriate |
| 329 | + // const TYPE_NOTYPE = 0; |
331 | 330 | break; |
332 | 331 | |
333 | 332 | case 1: |
334 | | -// /// Data item ID for SMWDINumber |
335 | | -// const TYPE_NUMBER = 1; |
| 333 | + // /// Data item ID for SMWDINumber |
| 334 | + // const TYPE_NUMBER = 1; |
336 | 335 | $solritem->addField( $propertyName . '_i', $di->getNumber() ); |
337 | 336 | $solritem->addSortField( $propertyName . '_i', $di->getNumber() ); |
338 | 337 | break; |
339 | 338 | |
340 | 339 | case 2: |
341 | | -// /// Data item ID for SMWDIString |
342 | | -// const TYPE_STRING = 2; |
| 340 | + // /// Data item ID for SMWDIString |
| 341 | + // const TYPE_STRING = 2; |
343 | 342 | $solritem->addField( $propertyName . '_t', $di->getString() ); |
344 | 343 | $solritem->addSortField( $propertyName . '_t', $di->getString() ); |
345 | 344 | break; |
346 | 345 | |
347 | 346 | case 3: |
348 | | -// /// Data item ID for SMWDIBlob |
349 | | -// const TYPE_BLOB = 3; |
| 347 | + // /// Data item ID for SMWDIBlob |
| 348 | + // const TYPE_BLOB = 3; |
350 | 349 | $solritem->addField( $propertyName . '_t', $di->getString() ); |
351 | 350 | $solritem->addSortField( $propertyName . '_t', $di->getString() ); |
352 | 351 | break; |
353 | 352 | |
354 | 353 | case 4: |
355 | | -// /// Data item ID for SMWDIBoolean |
356 | | -// const TYPE_BOOLEAN = 4; |
| 354 | + // /// Data item ID for SMWDIBoolean |
| 355 | + // const TYPE_BOOLEAN = 4; |
357 | 356 | $solritem->addField( $propertyName . '_b', $di->getBoolean() ); |
358 | 357 | $solritem->addSortField( $propertyName . '_b', $di->getBoolean() ); |
359 | 358 | break; |
360 | 359 | |
361 | 360 | case 5: |
362 | | -// /// Data item ID for SMWDIUri |
363 | | -// const TYPE_URI = 5; |
| 361 | + // /// Data item ID for SMWDIUri |
| 362 | + // const TYPE_URI = 5; |
364 | 363 | $solritem->addField( $propertyName . '_t', $di->getURI() ); |
365 | 364 | $solritem->addSortField( $propertyName . '_t', $di->getURI() ); |
366 | 365 | break; |
367 | 366 | |
368 | 367 | case 6: |
369 | | -// /// Data item ID for SMWDITimePoint |
370 | | -// const TYPE_TIME = 6; |
| 368 | + // /// Data item ID for SMWDITimePoint |
| 369 | + // const TYPE_TIME = 6; |
371 | 370 | $date = $di->getYear() . '-' . $di->getMonth() . '-' . $di->getDay() . 'T' . $di->getHour() . ':' . $di->getMinute() . ':' . $di->getSecond() . 'Z'; |
372 | 371 | $solritem->addField( $propertyName . '_dt', $date ); |
373 | 372 | $solritem->addSortField( $propertyName . '_dt', $date ); |
374 | 373 | break; |
375 | 374 | |
376 | 375 | case 7: |
377 | | -// /// Data item ID for SMWDIGeoCoord |
378 | | -// const TYPE_GEO = 7; |
| 376 | + // /// Data item ID for SMWDIGeoCoord |
| 377 | + // const TYPE_GEO = 7; |
379 | 378 | // TODO: Implement range Search in SOLR |
380 | 379 | $solritem->addField( $propertyName . '_lat', $di->getLatitude() ); |
381 | 380 | $solritem->addField( $propertyName . '_lng', $di->getLongitude() ); |
382 | 381 | break; |
383 | 382 | |
384 | 383 | case 8: |
385 | | -// /// Data item ID for SMWDIContainer |
386 | | -// const TYPE_CONTAINER = 8 |
387 | | - // TODO: What the Hell is this used for ??? |
388 | | - $data->getSubject()->getTitle()->getText() . " : "; |
| 384 | + // /// Data item ID for SMWDIContainer |
| 385 | + // const TYPE_CONTAINER = 8 |
| 386 | + // TODO: What the hell is this used for? |
| 387 | + $data->getSubject()->getTitle()->getText() . ' : '; |
389 | 388 | break; |
390 | 389 | |
391 | 390 | case 9: |
392 | | -// /// Data item ID for SMWDIWikiPage |
393 | | -// const TYPE_WIKIPAGE = 9; |
| 391 | + // /// Data item ID for SMWDIWikiPage |
| 392 | + // const TYPE_WIKIPAGE = 9; |
394 | 393 | $ns = $di->getNamespace(); |
395 | 394 | if ( $ns == 0 ) { |
396 | 395 | $solritem->addField( $propertyName . '_s', $di->getTitle() ); |
— | — | @@ -400,21 +399,21 @@ |
401 | 400 | break; |
402 | 401 | |
403 | 402 | case 10: |
404 | | -// /// Data item ID for SMWDIConcept |
405 | | -// const TYPE_CONCEPT = 10; |
406 | | - $data->getSubject()->getTitle()->getText() . " : "; |
| 403 | + // /// Data item ID for SMWDIConcept |
| 404 | + // const TYPE_CONCEPT = 10; |
| 405 | + $data->getSubject()->getTitle()->getText() . ' : '; |
407 | 406 | break; |
408 | 407 | |
409 | 408 | case 11: |
410 | | -// /// Data item ID for SMWDIProperty |
411 | | -// const TYPE_PROPERTY = 11; |
412 | | - $data->getSubject()->getTitle()->getText() . " : "; |
| 409 | + // /// Data item ID for SMWDIProperty |
| 410 | + // const TYPE_PROPERTY = 11; |
| 411 | + $data->getSubject()->getTitle()->getText() . ' : '; |
413 | 412 | break; |
414 | 413 | |
415 | 414 | case 12: |
416 | | -// /// Data item ID for SMWDIError |
417 | | -// const TYPE_ERROR = 12; |
418 | | - $data->getSubject()->getTitle()->getText() . " : "; |
| 415 | + // /// Data item ID for SMWDIError |
| 416 | + // const TYPE_ERROR = 12; |
| 417 | + $data->getSubject()->getTitle()->getText() . ' : '; |
419 | 418 | break; |
420 | 419 | default: |
421 | 420 | break; |
Index: trunk/extensions/SolrStore/SolrDoc.php |
— | — | @@ -14,34 +14,35 @@ |
15 | 15 | */ |
16 | 16 | class SolrDoc { |
17 | 17 | private $output; |
18 | | - private $min = array (); |
19 | | - private $max = array (); |
| 18 | + private $min = array(); |
| 19 | + private $max = array(); |
20 | 20 | |
21 | 21 | /** |
22 | | - * Add a Field to the SolrDoc |
| 22 | + * Add a field to the SolrDoc |
23 | 23 | * |
24 | | - * @param type $name of the Field |
25 | | - * @param type $value of the Field |
| 24 | + * @param $name String: name of the field |
| 25 | + * @param $value String: value of the field |
26 | 26 | */ |
27 | 27 | public function addField( $name, $value ) { |
28 | | - $this->output .= '<field name="' . $name . '">' . $value . '</field>' ; |
| 28 | + $this->output .= '<field name="' . $name . '">' . $value . '</field>'; |
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
32 | | - * This Function gets a Multivalued Field and splits it into a max and a min value for Sorting |
| 32 | + * This function gets a multivalued field and splits it into a max and a |
| 33 | + * min value for sorting |
33 | 34 | * |
34 | | - * @param type $name of the Field |
35 | | - * @param type $value of the Field |
| 35 | + * @param $name String: name of the field |
| 36 | + * @param $value Mixed: value of the field |
36 | 37 | */ |
37 | 38 | 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] ) ) { |
| 39 | + // Does a min/max field with this name exist? |
| 40 | + if ( isset( $this->min[$name] ) && isset( $this->max[$name] ) ) { |
40 | 41 | if ( strcasecmp( $this->min[$name], $value ) > 0 ) { |
41 | | - // If the new String is Less the Old one replace them |
| 42 | + // If the new string is less the old one, replace them |
42 | 43 | $this->min[$name] = $value; |
43 | 44 | } |
44 | 45 | if ( strcasecmp( $this->max[$name], $value ) < 0 ) { |
45 | | - // If the new String is Bigger than Old one replace them |
| 46 | + // If the new string is bigger than old one, replace them |
46 | 47 | $this->max[$name] = $value; |
47 | 48 | } |
48 | 49 | } else { |
— | — | @@ -54,10 +55,10 @@ |
55 | 56 | $all = $this->output; |
56 | 57 | |
57 | 58 | foreach ( $this->min as $name => $value ) { |
58 | | - $all .= '<field name="' . $name . 'min">' . $value . '</field>' ; |
| 59 | + $all .= '<field name="' . $name . 'min">' . $value . '</field>'; |
59 | 60 | } |
60 | 61 | foreach ( $this->max as $name => $value ) { |
61 | | - $all .= '<field name="' . $name . 'max">' . $value . '</field>' ; |
| 62 | + $all .= '<field name="' . $name . 'max">' . $value . '</field>'; |
62 | 63 | } |
63 | 64 | |
64 | 65 | return $all; |
Index: trunk/extensions/SolrStore/SolrSearch.php |
— | — | @@ -32,10 +32,16 @@ |
33 | 33 | * |
34 | 34 | * @param string $term - Raw search term |
35 | 35 | * @return SolrSearchSet |
36 | | - * @access public |
37 | 36 | */ |
38 | | - function searchText( $term ) { |
39 | | - return SolrSearchSet::newFromQuery( isset( $this->related ) ? 'related' : 'search', $term, $this->namespaces, $this->limit, $this->offset, $this->searchingEverything() ); |
| 37 | + public function searchText( $term ) { |
| 38 | + return SolrSearchSet::newFromQuery( |
| 39 | + isset( $this->related ) ? 'related' : 'search', |
| 40 | + $term, |
| 41 | + $this->namespaces, |
| 42 | + $this->limit, |
| 43 | + $this->offset, |
| 44 | + $this->searchingEverything() |
| 45 | + ); |
40 | 46 | } |
41 | 47 | |
42 | 48 | /** |
— | — | @@ -43,17 +49,16 @@ |
44 | 50 | * |
45 | 51 | * @param string $term - Raw search term |
46 | 52 | * @return SolrSearchSet |
47 | | - * @access public |
48 | 53 | */ |
49 | | - function searchTitle( $term ) { |
| 54 | + public function searchTitle( $term ) { |
50 | 55 | return null; |
51 | 56 | } |
52 | 57 | |
53 | 58 | /** |
54 | | - * PrefixSearchBackend override for OpenSearch results |
| 59 | + * PrefixSearchBackend override for OpenSearch results |
55 | 60 | */ |
56 | 61 | static function prefixSearch( $ns, $search, $limit, &$results ) { |
57 | | - echo "Prefix Search!<br/>"; |
| 62 | + echo 'Prefix Search!<br />'; // @todo Is this a debug line? Certainly looks like one...if so, comment out/remove! |
58 | 63 | $it = SolrSearchSet::newFromQuery( 'prefix', $search, $ns, $limit, 0 ); |
59 | 64 | $results = array(); |
60 | 65 | if ( $it ) { // $it can be null |
— | — | @@ -88,38 +93,42 @@ |
89 | 94 | */ |
90 | 95 | function replacePrefixes( $query ) { |
91 | 96 | global $wgContLang, $wgSolrUseRelated; |
92 | | - $fname = 'SolrSearch::replacePrefixes'; |
93 | | - wfProfileIn( $fname ); |
| 97 | + |
| 98 | + wfProfileIn( __METHOD__ ); |
94 | 99 | $start = 0; |
95 | 100 | $len = 0; // token start pos and length |
96 | 101 | $rewritten = ''; // rewritten query |
97 | 102 | $rindex = 0; // point to last rewritten character |
98 | 103 | $inquotes = false; |
99 | 104 | |
100 | | -// "search everything" keyword |
| 105 | + // "search everything" keyword |
101 | 106 | $allkeyword = wfMsgForContent( 'searchall' ); |
102 | 107 | |
103 | 108 | $qlen = strlen( $query ); |
104 | 109 | |
105 | | -// quick check, most of the time we don't need any rewriting |
| 110 | + // quick check, most of the time we don't need any rewriting |
106 | 111 | if ( strpos( $query, ':' ) === false ) { |
107 | | - wfProfileOut( $fname ); |
| 112 | + wfProfileOut( __METHOD__ ); |
108 | 113 | return $query; |
109 | 114 | } |
110 | 115 | |
111 | | -// check if this is query for related articles |
| 116 | + // check if this is query for related articles |
112 | 117 | $relatedkey = wfMsgForContent( 'searchrelated' ) . ':'; |
113 | 118 | if ( $wgSolrUseRelated && strncmp( $query, $relatedkey, strlen( $relatedkey ) ) == 0 ) { |
114 | 119 | $this->related = true; |
115 | | - list( $dummy, $ret ) = explode( ":", $query, 2 ); |
116 | | - wfProfileOut( $fname ); |
| 120 | + list( $dummy, $ret ) = explode( ':', $query, 2 ); |
| 121 | + wfProfileOut( __METHOD__ ); |
117 | 122 | return trim( $ret ); |
118 | 123 | } |
119 | 124 | |
120 | 125 | global $wgCanonicalNamespaceNames, $wgNamespaceAliases; |
121 | | - $nsNamesRaw = array_merge( $wgContLang->getNamespaces(), $wgCanonicalNamespaceNames, array_keys( array_merge( $wgNamespaceAliases, $wgContLang->getNamespaceAliases() ) ) ); |
| 126 | + $nsNamesRaw = array_merge( |
| 127 | + $wgContLang->getNamespaces(), |
| 128 | + $wgCanonicalNamespaceNames, |
| 129 | + array_keys( array_merge( $wgNamespaceAliases, $wgContLang->getNamespaceAliases() ) ) |
| 130 | + ); |
122 | 131 | |
123 | | -# add all namespace names w/o spaces |
| 132 | + # add all namespace names w/o spaces |
124 | 133 | $nsNames = array(); |
125 | 134 | foreach ( $nsNamesRaw as $ns ) { |
126 | 135 | if ( $ns != '' ) { |
— | — | @@ -130,7 +139,7 @@ |
131 | 140 | |
132 | 141 | $regexp = implode( '|', array_unique( $nsNames ) ); |
133 | 142 | |
134 | | -# rewrite the query by replacing valid namespace names |
| 143 | + # rewrite the query by replacing valid namespace names |
135 | 144 | $parts = preg_split( '/(")/', $query, -1, PREG_SPLIT_DELIM_CAPTURE ); |
136 | 145 | $inquotes = false; |
137 | 146 | $rewritten = ''; |
— | — | @@ -141,13 +150,14 @@ |
142 | 151 | } elseif ( $inquotes ) { |
143 | 152 | $rewritten .= $part; |
144 | 153 | } else { |
145 | | -# replace namespaces |
| 154 | + # replace namespaces |
146 | 155 | $r = preg_replace_callback( '/(^|[| :])(' . $regexp . '):/i', array( $this, 'replaceNamespace' ), $part ); |
147 | | -# replace to backend all: notation |
| 156 | + # replace to backend all: notation |
148 | 157 | $rewritten .= str_replace( $allkeyword . ':', 'all:', $r ); |
149 | 158 | } |
150 | 159 | } |
151 | | - wfProfileOut( $fname ); |
| 160 | + |
| 161 | + wfProfileOut( __METHOD__ ); |
152 | 162 | return $rewritten; |
153 | 163 | } |
154 | 164 | |
— | — | @@ -155,10 +165,11 @@ |
156 | 166 | function replaceNamespace( $matches ) { |
157 | 167 | global $wgContLang; |
158 | 168 | $inx = $wgContLang->getNsIndex( str_replace( ' ', '_', $matches[2] ) ); |
159 | | - if ( $inx === false ) |
| 169 | + if ( $inx === false ) { |
160 | 170 | return $matches[0]; |
161 | | - else |
| 171 | + } else { |
162 | 172 | return $matches[1] . "[$inx]:"; |
| 173 | + } |
163 | 174 | } |
164 | 175 | |
165 | 176 | function acceptListRedirects() { |
— | — | @@ -170,9 +181,10 @@ |
171 | 182 | global $wgSolrSearchVersion; |
172 | 183 | |
173 | 184 | if ( $wgSolrSearchVersion >= 2.1 && $this->prefix != '' ) { |
174 | | -# convert to internal backend prefix notation |
| 185 | + # convert to internal backend prefix notation |
175 | 186 | $term = $term . ' prefix:' . $this->prefix; |
176 | 187 | } |
| 188 | + |
177 | 189 | return $term; |
178 | 190 | } |
179 | 191 | |
— | — | @@ -203,34 +215,33 @@ |
204 | 216 | $xml = $result; |
205 | 217 | wfDebug( "Solr line: '$result'\n" ); |
206 | 218 | |
207 | | - // Defining Results |
| 219 | + // Defining results |
208 | 220 | |
209 | 221 | $this->mDate = null; |
210 | 222 | $score = $xml->float; |
211 | 223 | $this->mScore = $score; |
212 | 224 | |
213 | | - |
214 | 225 | // ------------------------------------- |
215 | | - // Get The Shit out of da XML |
| 226 | + // Get the shit out of the XML |
216 | 227 | // ------------------------------------- |
217 | 228 | foreach ( $xml->arr as $doc ) { |
218 | 229 | switch ( $doc['name'] ) { |
219 | 230 | case 'text': |
220 | 231 | $nsText = $doc->str; |
221 | 232 | |
222 | | - $this->mSize = ""; |
| 233 | + $this->mSize = ''; |
223 | 234 | $this->mWordCount = count( $doc->str ); |
224 | 235 | $snipmax = 10; |
225 | | - $textsnip = ""; |
| 236 | + $textsnip = ''; |
226 | 237 | $textsnipvar = 0; |
227 | 238 | foreach ( $doc->str as $inner ) { |
228 | 239 | $textsnipvar++; |
229 | 240 | if ( $textsnipvar >= 4 && $textsnipvar <= $snipmax ) { |
230 | | - $textsnip .= " " . $inner; |
| 241 | + $textsnip .= ' ' . $inner; |
231 | 242 | } |
232 | 243 | $this->mSize = $this->mSize + strlen( $inner ); |
233 | 244 | } |
234 | | - $textsnip .= "..."; |
| 245 | + $textsnip .= '...'; |
235 | 246 | $this->mSize = ( $this->mSize / 3 ); |
236 | 247 | // $this->mSize=$size; |
237 | 248 | break; |
— | — | @@ -253,6 +264,7 @@ |
254 | 265 | break; |
255 | 266 | } |
256 | 267 | } |
| 268 | + |
257 | 269 | foreach ( $xml->int as $doci ) { |
258 | 270 | switch ( $doci['name'] ) { |
259 | 271 | case 'namespace': |
— | — | @@ -262,29 +274,30 @@ |
263 | 275 | } |
264 | 276 | |
265 | 277 | $title = urldecode( $title ); |
266 | | - if ( !isset( $nsText ) ) |
| 278 | + if ( !isset( $nsText ) ) { |
267 | 279 | $nsText = $wgContLang->getNsText( $namespace ); |
268 | | - else |
| 280 | + } else { |
269 | 281 | $nsText = urldecode( $nsText ); |
| 282 | + } |
270 | 283 | |
271 | 284 | // make title |
272 | 285 | $this->mTitle = Title::makeTitle( $namespace, $title ); |
273 | 286 | |
274 | | - // HIGHLIHT |
275 | | - // <em> & </em> Fix to <b> // if not, no highlighting !! |
| 287 | + // HIGHLIGHT |
| 288 | + // <em> & </em> Fix to <b> // if not, no highlighting! |
276 | 289 | // TITLE (LINK) |
277 | 290 | if ( $xml->highlight->title != '' ) { |
278 | | - $this->mHighlightTitle = str_replace( "<em>", "<b>", $xml->highlight->title ); |
279 | | - $this->mHighlightTitle = str_replace( "</em>", "</b>", $this->mHighlightTitle ); |
| 291 | + $this->mHighlightTitle = str_replace( '<em>', '<b>', $xml->highlight->title ); |
| 292 | + $this->mHighlightTitle = str_replace( '</em>', '</b>', $this->mHighlightTitle ); |
280 | 293 | } else { |
281 | 294 | $this->mHighlightTitle = ''; |
282 | 295 | } |
283 | | - // TEXT (under Link) |
| 296 | + // TEXT (under link) |
284 | 297 | // $this->mHighlightText=$xml->highlight->title; |
285 | 298 | 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 .= "..."; |
| 299 | + $this->mHighlightText = str_replace( '<em>', '<b>', $xml->highlight->Inhalt ); |
| 300 | + $this->mHighlightText = str_replace( '</em>', '</b>', $this->mHighlightText ); |
| 301 | + $this->mHighlightText .= '...'; |
289 | 302 | } else {// $this->mHighlightText=textsnip; |
290 | 303 | if ( isset( $_REQUEST['search'] ) != '' && isset( $textsnip ) != '' ) { |
291 | 304 | if ( strpos( strtolower( $textsnip ), strtolower( $_REQUEST['search'] ) ) ) { |
— | — | @@ -292,7 +305,7 @@ |
293 | 306 | $pos1 = strpos( strtolower( $textsnip ), strtolower( $_REQUEST['search'] ) ); |
294 | 307 | $tmpa = substr( $textsnip, 0, $pos1 ); |
295 | 308 | $tmpb = substr( $textsnip, ( $pos1 + $tempc ) ); |
296 | | - $this->mHighlightText = $tmpa . "<b>" . substr( $textsnip, $pos1, $tempc ) . "</b>" . $tmpb; |
| 309 | + $this->mHighlightText = $tmpa . '<b>' . substr( $textsnip, $pos1, $tempc ) . '</b>' . $tmpb; |
297 | 310 | // str_replace($_REQUEST['search'],"<b>".$_REQUEST['search']."</b>",$textsnip); |
298 | 311 | } else { |
299 | 312 | $this->mHighlightText = $textsnip; |
— | — | @@ -316,17 +329,19 @@ |
317 | 330 | * @return array (highlighted, unmodified text) |
318 | 331 | */ |
319 | 332 | function extractSnippet( $lines, $nsText, $type, $useFinalSeparator = false ) { |
320 | | - if ( !array_key_exists( $type, $lines ) ) |
| 333 | + if ( !array_key_exists( $type, $lines ) ) { |
321 | 334 | return array( null, null ); |
322 | | - $ret = ""; |
| 335 | + } |
| 336 | + $ret = ''; |
323 | 337 | $original = null; |
324 | 338 | foreach ( $lines[$type] as $h ) { |
325 | 339 | list( $s, $o ) = $this->extractSnippetLine( $h, $useFinalSeparator ); |
326 | 340 | $ret .= $s; |
327 | 341 | $original = $o; |
328 | 342 | } |
329 | | - if ( $nsText != '' ) |
| 343 | + if ( $nsText != '' ) { |
330 | 344 | $ret = $nsText . ':' . $ret; |
| 345 | + } |
331 | 346 | return array( $ret, $original ); |
332 | 347 | } |
333 | 348 | |
— | — | @@ -339,41 +354,44 @@ |
340 | 355 | * @return array(snippet,unmodified text) |
341 | 356 | */ |
342 | 357 | function extractSnippetLine( $line, $useFinalSeparator ) { |
343 | | - $parts = explode( " ", $line ); |
| 358 | + $parts = explode( ' ', $line ); |
344 | 359 | if ( count( $parts ) != 4 && count( $parts ) != 5 ) { |
345 | 360 | wfDebug( "Bad result line:" . $line . "\n" ); |
346 | | - return ""; |
| 361 | + return ''; |
347 | 362 | } |
348 | 363 | $splits = $this->stripBracketsSplit( $parts[0] ); |
349 | 364 | $highlight = $this->stripBracketsSplit( $parts[1] ); |
350 | 365 | $suffix = urldecode( $this->stripBrackets( $parts[2] ) ); |
351 | 366 | $text = urldecode( $parts[3] ); |
352 | 367 | $original = null; |
353 | | - if ( count( $parts ) > 4 ) |
| 368 | + if ( count( $parts ) > 4 ) { |
354 | 369 | $original = urldecode( $parts[4] ); |
| 370 | + } |
355 | 371 | |
356 | 372 | $splits[] = strlen( $text ); |
357 | 373 | $start = 0; |
358 | | - $snippet = ""; |
| 374 | + $snippet = ''; |
359 | 375 | $hi = 0; |
360 | 376 | $ellipsis = wfMsgForContent( 'ellipsis' ); |
361 | 377 | |
362 | 378 | foreach ( $splits as $sp ) { |
363 | 379 | $sp = intval( $sp ); |
364 | | -// highlight words! |
| 380 | + // highlight words! |
365 | 381 | while ( $hi < count( $highlight ) && intval( $highlight[$hi] ) < $sp ) { |
366 | 382 | $s = intval( $highlight[$hi] ); |
367 | 383 | $e = intval( $highlight[$hi + 1] ); |
368 | | - $snippet .= substr( $text, $start, $s - $start ) . "<span class='searchmatch'>" . substr( $text, $s, $e - $s ) . "</span>"; |
| 384 | + $snippet .= substr( $text, $start, $s - $start ) . |
| 385 | + '<span class="searchmatch">' . substr( $text, $s, $e - $s ) . '</span>'; |
369 | 386 | $start = $e; |
370 | 387 | $hi += 2; |
371 | 388 | } |
372 | | -// copy till split point |
| 389 | + // copy till split point |
373 | 390 | $snippet .= substr( $text, $start, $sp - $start ); |
374 | | - if ( $sp == strlen( $text ) && $suffix != '' ) |
| 391 | + if ( $sp == strlen( $text ) && $suffix != '' ) { |
375 | 392 | $snippet .= $suffix; |
376 | | - else if ( $useFinalSeparator ) |
377 | | - $snippet .= " <b>" . $ellipsis . "</b> "; |
| 393 | + } elseif ( $useFinalSeparator ) { |
| 394 | + $snippet .= ' <b>' . $ellipsis . '</b> '; |
| 395 | + } |
378 | 396 | |
379 | 397 | $start = $sp; |
380 | 398 | } |
— | — | @@ -384,8 +402,9 @@ |
385 | 403 | * @access private |
386 | 404 | */ |
387 | 405 | function stripBrackets( $str ) { |
388 | | - if ( $str == '[]' ) |
| 406 | + if ( $str == '[]' ) { |
389 | 407 | return ''; |
| 408 | + } |
390 | 409 | return substr( $str, 1, strlen( $str ) - 2 ); |
391 | 410 | } |
392 | 411 | |
— | — | @@ -395,10 +414,11 @@ |
396 | 415 | */ |
397 | 416 | function stripBracketsSplit( $str ) { |
398 | 417 | $strip = $this->stripBrackets( $str ); |
399 | | - if ( $strip == '' ) |
| 418 | + if ( $strip == '' ) { |
400 | 419 | return array(); |
401 | | - else |
402 | | - return explode( ",", $strip ); |
| 420 | + } else { |
| 421 | + return explode( ',', $strip ); |
| 422 | + } |
403 | 423 | } |
404 | 424 | |
405 | 425 | function getTitle() { |
— | — | @@ -406,22 +426,24 @@ |
407 | 427 | } |
408 | 428 | |
409 | 429 | function getScore() { |
410 | | - if ( is_null( $this->mScore ) ) |
| 430 | + if ( is_null( $this->mScore ) ) { |
411 | 431 | return null; // Solr scores are meaningless to the user... |
| 432 | + } |
412 | 433 | |
413 | | -// echo($this->mScore." "); |
414 | 434 | return floatval( $this->mScore ); |
415 | 435 | } |
416 | 436 | |
417 | 437 | function getTitleSnippet( $terms ) { |
418 | | - if ( is_null( $this->mHighlightTitle ) ) |
| 438 | + if ( is_null( $this->mHighlightTitle ) ) { |
419 | 439 | return ''; |
| 440 | + } |
420 | 441 | return $this->mHighlightTitle; |
421 | 442 | } |
422 | 443 | |
423 | 444 | function getTextSnippet( $terms ) { |
424 | | - if ( is_null( $this->mHighlightText ) ) |
| 445 | + if ( is_null( $this->mHighlightText ) ) { |
425 | 446 | return parent::getTextSnippet( $terms ); |
| 447 | + } |
426 | 448 | return $this->mHighlightText; |
427 | 449 | } |
428 | 450 | |
— | — | @@ -439,14 +461,16 @@ |
440 | 462 | } |
441 | 463 | |
442 | 464 | function getSectionSnippet() { |
443 | | - if ( is_null( $this->mHighlightSection ) ) |
| 465 | + if ( is_null( $this->mHighlightSection ) ) { |
444 | 466 | return null; |
| 467 | + } |
445 | 468 | return $this->mHighlightSection; |
446 | 469 | } |
447 | 470 | |
448 | 471 | function getSectionTitle() { |
449 | | - if ( is_null( $this->mSectionTitle ) ) |
| 472 | + if ( is_null( $this->mSectionTitle ) ) { |
450 | 473 | return null; |
| 474 | + } |
451 | 475 | return $this->mSectionTitle; |
452 | 476 | } |
453 | 477 | |
— | — | @@ -459,20 +483,23 @@ |
460 | 484 | } |
461 | 485 | |
462 | 486 | function getTimestamp() { |
463 | | - if ( is_null( $this->mDate ) ) |
| 487 | + if ( is_null( $this->mDate ) ) { |
464 | 488 | return parent::getTimestamp(); |
| 489 | + } |
465 | 490 | return $this->mDate; |
466 | 491 | } |
467 | 492 | |
468 | 493 | function getWordCount() { |
469 | | - if ( is_null( $this->mWordCount ) ) |
| 494 | + if ( is_null( $this->mWordCount ) ) { |
470 | 495 | return parent::getWordCount(); |
| 496 | + } |
471 | 497 | return $this->mWordCount; |
472 | 498 | } |
473 | 499 | |
474 | 500 | function getByteSize() { |
475 | | - if ( is_null( $this->mSize ) ) |
| 501 | + if ( is_null( $this->mSize ) ) { |
476 | 502 | return parent::getByteSize(); |
| 503 | + } |
477 | 504 | return $this->mSize; |
478 | 505 | } |
479 | 506 | |
— | — | @@ -489,22 +516,20 @@ |
490 | 517 | * Contact the MWDaemon search server and return a wrapper |
491 | 518 | * object with the set of results. Results may be cached. |
492 | 519 | * |
493 | | - * @param string $method The protocol verb to use |
494 | | - * @param string $query |
495 | | - * @param int $limit |
496 | | - * @param int $offset |
497 | | - * @param bool $searchAll |
| 520 | + * @param $method String: the protocol verb to use |
| 521 | + * @param $query String |
| 522 | + * @param $limit Integer |
| 523 | + * @param $offset Integer |
| 524 | + * @param $searchAll Boolean |
498 | 525 | * @return array |
499 | | - * @access public |
500 | 526 | */ |
501 | | - static function newFromQuery( $method, $query, $namespaces = array(), $limit = 20, $offset = 0, $searchAll = False ) { |
502 | | - $fname = 'SolrSearchSet::newFromQuery'; |
503 | | - wfProfileIn( $fname ); |
| 527 | + public static function newFromQuery( $method, $query, $namespaces = array(), $limit = 20, $offset = 0, $searchAll = false ) { |
| 528 | + wfProfileIn( __METHOD__ ); |
504 | 529 | |
505 | 530 | $wgSolrTalker = new SolrTalker(); |
506 | 531 | |
507 | 532 | $query = $wgSolrTalker->queryChecker( $query ); |
508 | | - $xml = $wgSolrTalker->solrQuery( $query, $offset, $limit, true, true ); // Abfrage ok, ergebniss in XML |
| 533 | + $xml = $wgSolrTalker->solrQuery( $query, $offset, $limit, true, true ); // Abfrage ok, ergebniss in XML |
509 | 534 | $totalHits = $xml->result['numFound']; |
510 | 535 | |
511 | 536 | $resultLines = array(); ; |
— | — | @@ -514,14 +539,10 @@ |
515 | 540 | $hli = 0; |
516 | 541 | |
517 | 542 | foreach ( $xml->result->doc as $doc ) { |
518 | | - |
519 | 543 | if ( isset( $highl[$hli]->arr ) ) { |
520 | | - |
521 | 544 | foreach ( $highl[$hli]->arr as $feld ) { |
522 | 545 | if ( isset( $feld['name'] ) ) { |
523 | | - |
524 | 546 | switch ( $feld['name'] ) { |
525 | | - |
526 | 547 | case 'title': |
527 | 548 | $doc[]->highlight->title = $feld->str; |
528 | 549 | break; |
— | — | @@ -536,16 +557,16 @@ |
537 | 558 | $resultLines[] = $doc; |
538 | 559 | } |
539 | 560 | |
540 | | - |
541 | 561 | $suggestion = null; |
542 | 562 | $info = null; |
543 | 563 | $interwiki = null; |
544 | 564 | |
| 565 | + $resultSet = new SolrSearchSet( |
| 566 | + $method, $query, $resultLines, count( $resultLines ), $totalHits, |
| 567 | + $suggestion, $info, $interwiki |
| 568 | + ); |
545 | 569 | |
546 | | - $resultSet = new SolrSearchSet( $method, $query, $resultLines, count( $resultLines ), $totalHits, |
547 | | - $suggestion, $info, $interwiki ); |
548 | | - |
549 | | - wfProfileOut( $fname ); |
| 570 | + wfProfileOut( __METHOD__ ); |
550 | 571 | return $resultSet; |
551 | 572 | } |
552 | 573 | |
— | — | @@ -581,17 +602,19 @@ |
582 | 603 | |
583 | 604 | /** Get suggestions from a suggestion result line */ |
584 | 605 | function parseSuggestion( $suggestion ) { |
585 | | - if ( is_null( $suggestion ) ) |
| 606 | + if ( is_null( $suggestion ) ) { |
586 | 607 | return; |
587 | | -// parse split points and highlight changes |
588 | | - list( $dummy, $points, $sug ) = explode( " ", $suggestion ); |
| 608 | + } |
| 609 | + |
| 610 | + // parse split points and highlight changes |
| 611 | + list( $dummy, $points, $sug ) = explode( ' ', $suggestion ); |
589 | 612 | $sug = urldecode( $sug ); |
590 | | - $points = explode( ",", substr( $points, 1, -1 ) ); |
| 613 | + $points = explode( ',', substr( $points, 1, -1 ) ); |
591 | 614 | array_unshift( $points, 0 ); |
592 | | - $suggestText = ""; |
| 615 | + $suggestText = ''; |
593 | 616 | for ( $i = 1; $i < count( $points ); $i += 2 ) { |
594 | 617 | $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>"; |
| 618 | + $suggestText .= '<em>' . htmlspecialchars( substr( $sug, $points[$i], $points[$i + 1] - $points[$i] ) ) . '</em>'; |
596 | 619 | } |
597 | 620 | $suggestText .= htmlspecialchars( substr( $sug, end( $points ) ) ); |
598 | 621 | |
— | — | @@ -601,19 +624,24 @@ |
602 | 625 | |
603 | 626 | /** replace prefixes like [2]: that are not in phrases */ |
604 | 627 | function replaceGenericPrefixes( $text ) { |
605 | | - $out = ""; |
| 628 | + $out = ''; |
606 | 629 | $phrases = explode( '"', $text ); |
607 | 630 | 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 ) ) |
| 631 | + $out .= preg_replace_callback( |
| 632 | + '/\[([0-9]+)\]:/', |
| 633 | + array( $this, 'genericPrefixCallback' ), |
| 634 | + $phrases[$i] |
| 635 | + ); |
| 636 | + if ( $i + 1 < count( $phrases ) ) { |
610 | 637 | $out .= '"' . $phrases[$i + 1] . '"'; // phrase text |
| 638 | + } |
611 | 639 | } |
612 | 640 | return $out; |
613 | 641 | } |
614 | 642 | |
615 | 643 | function genericPrefixCallback( $matches ) { |
616 | 644 | global $wgContLang; |
617 | | - return $wgContLang->getFormattedNsText( $matches[1] ) . ":"; |
| 645 | + return $wgContLang->getFormattedNsText( $matches[1] ) . ':'; |
618 | 646 | } |
619 | 647 | |
620 | 648 | function numRows() { |
— | — | @@ -621,25 +649,26 @@ |
622 | 650 | } |
623 | 651 | |
624 | 652 | function termMatches() { |
625 | | - $resq = preg_replace( "/\\[.*?\\]:/", " ", $this->mQuery ); # generic prefixes |
626 | | - $resq = preg_replace( "/all:/", " ", $resq ); |
| 653 | + $resq = preg_replace( "/\\[.*?\\]:/", ' ', $this->mQuery ); # generic prefixes |
| 654 | + $resq = preg_replace( '/all:/', ' ', $resq ); |
627 | 655 | |
628 | | -// Fixme: this is ripped from SearchMySQL and probably kind of sucks, |
629 | | -// but it handles quoted phrase searches more or less correctly. |
630 | | -// Should encapsulate this stuff better. |
631 | | -// FIXME: This doesn't handle parenthetical expressions. |
| 656 | + // @todo FIXME: this is ripped from SearchMySQL and probably kind of sucks, |
| 657 | + // but it handles quoted phrase searches more or less correctly. |
| 658 | + // Should encapsulate this stuff better. |
| 659 | + // @todo FIXME: This doesn't handle parenthetical expressions. |
632 | 660 | $regexes = array(); |
633 | 661 | $m = array(); |
634 | 662 | $lc = SearchEngine::legalSearchChars(); |
635 | 663 | if ( preg_match_all( '/([-+<>~]?)(([' . $lc . ']+)(\*?)|"[^"]*")/', $resq, $m, PREG_SET_ORDER ) ) { |
636 | 664 | foreach ( $m as $terms ) { |
637 | 665 | if ( !empty( $terms[3] ) ) { |
638 | | -// Match individual terms in result highlighting... |
| 666 | + // Match individual terms in result highlighting... |
639 | 667 | $regexp = preg_quote( $terms[3], '/' ); |
640 | | - if ( $terms[4] ) |
641 | | - $regexp .= "[0-9A-Za-z_]+"; |
| 668 | + if ( $terms[4] ) { |
| 669 | + $regexp .= '[0-9A-Za-z_]+'; |
| 670 | + } |
642 | 671 | } else { |
643 | | -// Match the quoted term in result highlighting... |
| 672 | + // Match the quoted term in result highlighting... |
644 | 673 | $regexp = preg_quote( str_replace( '"', '', $terms[2] ), '/' ); |
645 | 674 | } |
646 | 675 | $regexes[] = $regexp; |
— | — | @@ -670,9 +699,8 @@ |
671 | 700 | * settings. |
672 | 701 | * |
673 | 702 | * @return int |
674 | | - * @access public |
675 | 703 | */ |
676 | | - function getTotalHits() { |
| 704 | + public function getTotalHits() { |
677 | 705 | return $this->mTotalHits; |
678 | 706 | } |
679 | 707 | |
— | — | @@ -683,9 +711,10 @@ |
684 | 712 | * @return string |
685 | 713 | */ |
686 | 714 | function getInfo() { |
687 | | - if ( is_null( $this->mInfo ) ) |
| 715 | + if ( is_null( $this->mInfo ) ) { |
688 | 716 | return null; |
689 | | - return "Search results fetched via " . $this->mInfo; |
| 717 | + } |
| 718 | + return 'Search results fetched via ' . $this->mInfo; |
690 | 719 | } |
691 | 720 | |
692 | 721 | /** |
— | — | @@ -702,9 +731,8 @@ |
703 | 732 | * no exact hits. Returns true if there is one on this set. |
704 | 733 | * |
705 | 734 | * @return bool |
706 | | - * @access public |
707 | 735 | */ |
708 | | - function hasSuggestion() { |
| 736 | + public function hasSuggestion() { |
709 | 737 | return is_string( $this->mSuggestionQuery ) && $this->mSuggestionQuery != ''; |
710 | 738 | } |
711 | 739 | |
— | — | @@ -719,10 +747,9 @@ |
720 | 748 | /** |
721 | 749 | * Fetches next search result, or false. |
722 | 750 | * @return SolrResult |
723 | | - * @access public |
724 | 751 | * @abstract |
725 | 752 | */ |
726 | | - function next() { |
| 753 | + public function next() { |
727 | 754 | if ( $this->mPos < $this->mResultCount ) { |
728 | 755 | $this->mPos++; |
729 | 756 | return new SolrResult( $this->mResults[$this->mPos - 1], $this->mMethod ); |
Index: trunk/extensions/SolrStore/SpecialSolrSearch.php |
— | — | @@ -24,7 +24,7 @@ |
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; |
— | — | @@ -40,16 +40,12 @@ |
41 | 41 | $this->setHeaders(); |
42 | 42 | $SpecialSolrSearch = new SpecialSolrSearch( $wgRequest, $wgUser ); |
43 | 43 | |
44 | | - # Get request data from, e.g. |
45 | | - $param = $wgRequest->getText( 'param' ); |
46 | | - |
47 | 44 | foreach ( $wgSolrFields as $set ) { |
48 | 45 | if ( $par == $set->getName() ) { |
49 | 46 | $fieldSet = $set; |
50 | 47 | } |
51 | 48 | } |
52 | | - # Do stuff |
53 | | - # ... |
| 49 | + |
54 | 50 | // Strip underscores from title parameter; most of the time we'll want |
55 | 51 | // text form here. But don't strip underscores from actual text params! |
56 | 52 | $titleParam = str_replace( '_', ' ', $par ); |
— | — | @@ -63,13 +59,13 @@ |
64 | 60 | $firstTimeHere = true; |
65 | 61 | foreach ( $fieldSet->getFields() as $field ) { |
66 | 62 | if ( $firstTimeHere ) { |
67 | | - $newLable ['solr' . trim( $field )] = trim( $lable[0] ); |
| 63 | + $newLable['solr' . trim( $field )] = trim( $lable[0] ); |
68 | 64 | $firstTimeHere = false; |
69 | 65 | } else { |
70 | | - $newLable ['solr' . trim( $field )] = trim( next( $lable ) ); |
| 66 | + $newLable['solr' . trim( $field )] = trim( next( $lable ) ); |
71 | 67 | } |
72 | 68 | |
73 | | - $newFields ['solr' . trim( $field )] = $wgRequest->getText( 'solr' . trim( $field ) ); |
| 69 | + $newFields['solr' . trim( $field )] = $wgRequest->getText( 'solr' . trim( $field ) ); |
74 | 70 | } |
75 | 71 | $fieldSet->setFields( $newFields ); |
76 | 72 | $fieldSet->setLable( $newLable ); |
— | — | @@ -87,22 +83,21 @@ |
88 | 84 | |
89 | 85 | $sk = $wgUser->getSkin(); |
90 | 86 | |
91 | | - |
92 | 87 | $wgOut->setPageTitle( wfMsg( 'solrstore-searchFieldSets' ) ); |
93 | 88 | $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'solrstore-searchFieldSets-title', 'SolrSearch: Select FieldSet' ) ) ); |
94 | 89 | |
95 | 90 | $wgOut->setArticleRelated( false ); |
96 | | - $wgOut->addHtml( '<div class="solrsearch-fieldset">' ); |
97 | | - $wgOut->addHtml( wfMsg( 'solrstore-searchFieldSets-select' ) ); |
98 | | - $wgOut->addHtml( '<ul>' ); |
| 91 | + $wgOut->addHTML( '<div class="solrsearch-fieldset">' ); |
| 92 | + $wgOut->addHTML( wfMsg( 'solrstore-searchFieldSets-select' ) ); |
| 93 | + $wgOut->addHTML( '<ul>' ); |
99 | 94 | |
100 | 95 | // TODO: If no SearchSets exist, provide a shot Manual how to create some! |
101 | 96 | foreach ( $wgSolrFields as $set ) { |
102 | 97 | $name = $set->getName(); |
103 | | - $wgOut->addHtml( "<li><a href=\"$wgScript/Special:SolrSearch/$name\">$name</a></li>" ); |
| 98 | + $wgOut->addHTML( "<li><a href=\"$wgScript/Special:SolrSearch/$name\">$name</a></li>" ); |
104 | 99 | } |
105 | | - $wgOut->addHtml( '</ul>' ); |
106 | | - $wgOut->addHtml( "</div>" ); |
| 100 | + $wgOut->addHTML( '</ul>' ); |
| 101 | + $wgOut->addHTML( '</div>' ); |
107 | 102 | |
108 | 103 | wfProfileOut( __METHOD__ ); |
109 | 104 | } |
— | — | @@ -124,17 +119,16 @@ |
125 | 120 | |
126 | 121 | $t = Title::newFromText( $fieldSet->getName() ); |
127 | 122 | |
128 | | - // DO we have Title matches |
| 123 | + // Do we have title matches? |
129 | 124 | $fields = $fieldSet->getFields(); |
130 | 125 | |
131 | | - // BUILD SOLR QUERY STRING FROM DA FIELDS |
| 126 | + // Build Solr query string from the fields |
132 | 127 | if ( isset( $fields['solrsearch'] ) ) { |
133 | 128 | $query = $fields['solrsearch']; |
134 | 129 | } else { |
135 | 130 | $query = ''; |
136 | 131 | } |
137 | 132 | |
138 | | - |
139 | 133 | foreach ( $fields as $key => $value ) { |
140 | 134 | if ( $key != 'solrsearch' && !empty( $value ) ) { |
141 | 135 | $query = trim( $query ) . ' ' . trim( substr( $key, 4 ) ) . ':' . '(' . ( $value ) . ')'; |
— | — | @@ -147,8 +141,9 @@ |
148 | 142 | |
149 | 143 | $titleMatches = $search->searchTitle( $query ); |
150 | 144 | |
151 | | - if ( !( $titleMatches instanceof SearchResultTooMany ) ) |
| 145 | + if ( !( $titleMatches instanceof SearchResultTooMany ) ) { |
152 | 146 | $textMatches = $search->searchText( $query ); |
| 147 | + } |
153 | 148 | |
154 | 149 | // did you mean... suggestions |
155 | 150 | if ( $textMatches && $textMatches->hasSuggestion() ) { |
— | — | @@ -161,33 +156,37 @@ |
162 | 157 | |
163 | 158 | $suggestionSnippet = $textMatches->getSuggestionSnippet(); |
164 | 159 | |
165 | | - if ( $suggestionSnippet == '' ) |
| 160 | + if ( $suggestionSnippet == '' ) { |
166 | 161 | $suggestionSnippet = null; |
| 162 | + } |
167 | 163 | |
168 | 164 | $suggestLink = $sk->linkKnown( |
169 | | - $st, $suggestionSnippet, array(), $stParams |
| 165 | + $st, $suggestionSnippet, array(), $stParams |
170 | 166 | ); |
171 | 167 | |
172 | | - $this->didYouMeanHtml = '<div class="searchdidyoumean">' . wfMsg( 'search-suggest', $suggestLink ) . '</div>'; |
| 168 | + $this->didYouMeanHtml = '<div class="searchdidyoumean">' . |
| 169 | + wfMsg( 'search-suggest', $suggestLink ) . '</div>'; |
173 | 170 | } |
| 171 | + |
174 | 172 | // start rendering the page |
175 | | - $wgOut->addHtml( |
176 | | - Xml::openElement( |
177 | | - 'form', array( |
| 173 | + $wgOut->addHTML( |
| 174 | + Xml::openElement( |
| 175 | + 'form', |
| 176 | + array( |
178 | 177 | 'id' => 'solrsearch', |
179 | 178 | 'method' => 'get', |
180 | 179 | 'action' => $wgScript |
181 | | - ) |
182 | 180 | ) |
| 181 | + ) |
183 | 182 | ); |
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' ) |
| 183 | + $wgOut->addHTML( |
| 184 | + Xml::openElement( 'table', array( 'id' => 'mw-search-top-table', 'border' => 0, 'cellpadding' => 0, 'cellspacing' => 0 ) ) . |
| 185 | + Xml::openElement( 'tr' ) . |
| 186 | + Xml::openElement( 'td' ) . "\n" . |
| 187 | + $this->shortDialog( $fieldSet ) . |
| 188 | + Xml::closeElement( 'td' ) . |
| 189 | + Xml::closeElement( 'tr' ) . |
| 190 | + Xml::closeElement( 'table' ) |
192 | 191 | ); |
193 | 192 | |
194 | 193 | // Sometimes the search engine knows there are too many hits |
— | — | @@ -226,14 +225,19 @@ |
227 | 226 | // show number of results and current offset |
228 | 227 | $wgOut->addHTML( $this->formHeader( $query, $num, $totalRes ) ); |
229 | 228 | |
230 | | - $wgOut->addHtml( Xml::closeElement( 'form' ) ); |
231 | | - $wgOut->addHtml( "<div class='searchresults'>" ); |
| 229 | + $wgOut->addHTML( Xml::closeElement( 'form' ) ); |
| 230 | + $wgOut->addHTML( "<div class='searchresults'>" ); |
232 | 231 | |
233 | 232 | // prev/next links |
234 | 233 | if ( $num || $this->offset ) { |
235 | 234 | // Show the create link ahead |
236 | 235 | $this->showCreateLink( $t ); |
237 | | - $prevnext = wfViewPrevNext( $this->offset, $this->limit, SpecialPage::getTitleFor( 'SolrSearch' ), wfArrayToCGI( array( 'solrsearch' => $query ) ), max( $titleMatchesNum, $textMatchesNum ) < $this->limit |
| 236 | + $prevnext = wfViewPrevNext( |
| 237 | + $this->offset, |
| 238 | + $this->limit, |
| 239 | + SpecialPage::getTitleFor( 'SolrSearch' ), |
| 240 | + wfArrayToCGI( array( 'solrsearch' => $query ) ), |
| 241 | + max( $titleMatchesNum, $textMatchesNum ) < $this->limit |
238 | 242 | ); |
239 | 243 | // $wgOut->addHTML( "<p class='mw-search-pager-top'>{$prevnext}</p>\n" ); |
240 | 244 | wfRunHooks( 'SpecialSolrSearchResults', array( $fieldSet, &$titleMatches, &$textMatches ) ); |
— | — | @@ -266,7 +270,7 @@ |
267 | 271 | $textMatches->free(); |
268 | 272 | } |
269 | 273 | |
270 | | - $wgOut->addHtml( "</div>" ); |
| 274 | + $wgOut->addHTML( '</div>' ); |
271 | 275 | |
272 | 276 | if ( $num || $this->offset ) { |
273 | 277 | $wgOut->addHTML( "<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" ); |
— | — | @@ -289,7 +293,8 @@ |
290 | 294 | } |
291 | 295 | } |
292 | 296 | if ( $messageName ) { |
293 | | - $wgOut->wrapWikiMsg( "<p class=\"mw-search-createlink\">\n$1</p>", array( $messageName, wfEscapeWikiText( $t->getPrefixedText() ) ) ); |
| 297 | + $wgOut->wrapWikiMsg( "<p class=\"mw-search-createlink\">\n$1</p>", |
| 298 | + array( $messageName, wfEscapeWikiText( $t->getPrefixedText() ) ) ); |
294 | 299 | } else { |
295 | 300 | // preserve the paragraph for margins etc... |
296 | 301 | $wgOut->addHtml( '<p></p>' ); |
— | — | @@ -308,7 +313,7 @@ |
309 | 314 | } |
310 | 315 | $wgOut->setArticleRelated( false ); |
311 | 316 | $wgOut->setRobotPolicy( 'noindex,nofollow' ); |
312 | | - // add javascript specific to special:search |
| 317 | + // add JavaScript specific to Special:Search |
313 | 318 | $wgOut->addModules( 'mediawiki.legacy.search' ); |
314 | 319 | $wgOut->addModules( 'mediawiki.special.search' ); |
315 | 320 | } |
— | — | @@ -324,13 +329,12 @@ |
325 | 330 | |
326 | 331 | $fieldSets = $wgContLang->convertForSearchResult( $matches->termMatches() ); |
327 | 332 | |
328 | | - $out = ""; |
| 333 | + $out = ''; |
329 | 334 | $infoLine = $matches->getInfo(); |
330 | 335 | if ( !is_null( $infoLine ) ) { |
331 | 336 | $out .= "\n<!-- {$infoLine} -->\n"; |
332 | 337 | } |
333 | 338 | $out .= "<ul class='mw-search-results'>\n"; |
334 | | - $xxx = 0; |
335 | 339 | while ( $result = $matches->next() ) { |
336 | 340 | $out .= $this->showHit( $result, $fieldSets ); |
337 | 341 | } |
— | — | @@ -362,8 +366,9 @@ |
363 | 367 | |
364 | 368 | $titleSnippet = $result->getTitleSnippet( $fieldSets ); |
365 | 369 | |
366 | | - if ( $titleSnippet == '' ) |
| 370 | + if ( $titleSnippet == '' ) { |
367 | 371 | $titleSnippet = null; |
| 372 | + } |
368 | 373 | |
369 | 374 | $link_t = clone $t; |
370 | 375 | |
— | — | @@ -399,28 +404,30 @@ |
400 | 405 | $redirect = ''; |
401 | 406 | |
402 | 407 | if ( !is_null( $redirectTitle ) ) { |
403 | | - if ( $redirectText == '' ) |
| 408 | + if ( $redirectText == '' ) { |
404 | 409 | $redirectText = null; |
| 410 | + } |
405 | 411 | |
406 | | - $redirect = "<span class='searchalttitle'>" . |
407 | | - wfMsg( 'search-redirect', $this->sk->linkKnown( $redirectTitle, $redirectText ) ) . |
408 | | - "</span>"; |
| 412 | + $redirect = '<span class="searchalttitle">' . |
| 413 | + wfMsg( 'search-redirect', $this->sk->linkKnown( $redirectTitle, $redirectText ) ) . |
| 414 | + '</span>'; |
409 | 415 | } |
410 | 416 | |
411 | 417 | $section = ''; |
412 | 418 | |
413 | 419 | |
414 | 420 | if ( !is_null( $sectionTitle ) ) { |
415 | | - if ( $sectionText == '' ) |
| 421 | + if ( $sectionText == '' ) { |
416 | 422 | $sectionText = null; |
| 423 | + } |
417 | 424 | |
418 | | - $section = "<span class='searchalttitle'>" . |
| 425 | + $section = '<span class="searchalttitle">' . |
419 | 426 | wfMsg( 'search-section', $this->sk->linkKnown( $sectionTitle, $sectionText ) ) . |
420 | | - "</span>"; |
| 427 | + '</span>'; |
421 | 428 | } |
422 | 429 | |
423 | 430 | // format text extract |
424 | | - $extract = "<div class='searchresult'>" . $result->getTextSnippet( $fieldSets ) . "</div>"; |
| 431 | + $extract = '<div class="searchresult">' . $result->getTextSnippet( $fieldSets ) . '</div>'; |
425 | 432 | |
426 | 433 | // format score |
427 | 434 | if ( is_null( $result->getScore() ) ) { |
— | — | @@ -435,11 +442,15 @@ |
436 | 443 | $byteSize = $result->getByteSize(); |
437 | 444 | $wordCount = $result->getWordCount(); |
438 | 445 | $timestamp = $result->getTimestamp(); |
439 | | - $size = wfMsgExt( 'search-result-size', array( 'parsemag', 'escape' ), $this->sk->formatSize( $byteSize ), $wgLang->formatNum( $wordCount ) ); |
| 446 | + $size = wfMsgExt( 'search-result-size', array( 'parsemag', 'escape' ), |
| 447 | + $this->sk->formatSize( $byteSize ), $wgLang->formatNum( $wordCount ) ); |
440 | 448 | |
441 | 449 | if ( $t->getNamespace() == NS_CATEGORY ) { |
442 | 450 | $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() ) ); |
| 451 | + $size = wfMsgExt( 'search-result-category-size', array( 'parsemag', 'escape' ), |
| 452 | + $wgLang->formatNum( $cat->getPageCount() ), |
| 453 | + $wgLang->formatNum( $cat->getSubcatCount() ), |
| 454 | + $wgLang->formatNum( $cat->getFileCount() ) ); |
444 | 455 | } |
445 | 456 | |
446 | 457 | $date = $wgLang->timeanddate( $timestamp ); |
— | — | @@ -453,7 +464,7 @@ |
454 | 465 | } |
455 | 466 | |
456 | 467 | // Include a thumbnail for media files... |
457 | | - // WE HAVE NEVER TESTED THIS HERE!!! |
| 468 | + // WE HAVE NEVER TESTED THIS HERE! |
458 | 469 | if ( $t->getNamespace() == NS_FILE ) { |
459 | 470 | $img = wfFindFile( $t ); |
460 | 471 | if ( $img ) { |
— | — | @@ -464,7 +475,7 @@ |
465 | 476 | // Float doesn't seem to interact well with the bullets. |
466 | 477 | // Table messes up vertical alignment of the bullets. |
467 | 478 | // Bullets are therefore disabled (didn't look great anyway). |
468 | | - return "<li>" . |
| 479 | + return '<li>' . |
469 | 480 | '<table class="searchResultImage">' . |
470 | 481 | '<tr>' . |
471 | 482 | '<td width="120" align="center" valign="top">' . |
— | — | @@ -497,7 +508,13 @@ |
498 | 509 | // Results-info |
499 | 510 | if ( $resultsShown > 0 ) { |
500 | 511 | 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 ) |
| 512 | + $top = wfMsgExt( |
| 513 | + 'showingresultsheader', |
| 514 | + array( 'parseinline' ), |
| 515 | + $wgLang->formatNum( $this->offset + 1 ), |
| 516 | + $wgLang->formatNum( $this->offset + $resultsShown ), |
| 517 | + $wgLang->formatNum( $totalNum ), |
| 518 | + $wgLang->formatNum( $resultsShown ) |
502 | 519 | ); |
503 | 520 | } elseif ( $resultsShown >= $this->limit ) { |
504 | 521 | $top = wfShowingResults( $this->offset, $this->limit ); |
— | — | @@ -516,7 +533,6 @@ |
517 | 534 | protected function shortDialog( $fieldSet ) { |
518 | 535 | $searchTitle = SpecialPage::getTitleFor( 'SolrSearch' ); |
519 | 536 | |
520 | | - |
521 | 537 | if ( $fieldSet->getName() != 'search' ) { |
522 | 538 | $out = Html::hidden( 'title', $searchTitle->getPrefixedText() . '/' . $fieldSet->getName() ) . "\n"; |
523 | 539 | } else { |
— | — | @@ -534,10 +550,10 @@ |
535 | 551 | } |
536 | 552 | $out .= '<td>'; |
537 | 553 | $out .= Html::input( $key, $value, $key, array( |
538 | | - 'id' => $key, |
539 | | - 'size' => '50', |
540 | | - 'autofocus' |
541 | | - ) ) . "\n"; |
| 554 | + 'id' => $key, |
| 555 | + 'size' => '50', |
| 556 | + 'autofocus' |
| 557 | + ) ) . "\n"; |
542 | 558 | $out .= '</td></tr>'; |
543 | 559 | } |
544 | 560 | $out .= '<table>'; |
Index: trunk/extensions/SolrStore/SolrConnectorStore.php |
— | — | @@ -151,7 +151,6 @@ |
152 | 152 | * $redirid will be 0. |
153 | 153 | */ |
154 | 154 | public function changeTitle( Title $oldtitle, Title $newtitle, $pageid, $redirid = 0 ) { |
155 | | - |
156 | 155 | // TODO: Update Solr to reflect a renaming of some article |
157 | 156 | return self::getBaseStore()->changeTitle( $oldtitle, $newtitle, $pageid, $redirid ); |
158 | 157 | } |
— | — | @@ -171,9 +170,10 @@ |
172 | 171 | */ |
173 | 172 | public function getQueryResult( SMWQuery $query ) { |
174 | 173 | // 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 |
| 174 | + // Our first aproche was it to create new SMWStore for querying data |
| 175 | + // but we had big problems recreating and parsing the SMW query syntax |
| 176 | + // that we just stopped at this point here. |
| 177 | + // Maybe we will finish it someday |
178 | 178 | $wgSolrTalker = new SolrTalker(); |
179 | 179 | if ( property_exists( $query, 'params' ) && |
180 | 180 | array_key_exists( 'source', $query->params ) && |
— | — | @@ -186,10 +186,9 @@ |
187 | 187 | |
188 | 188 | echo( "SOLR query: {$query->getQueryString()}\n" ); |
189 | 189 | |
190 | | - echo( "Search is Powered by Solr!" ); |
| 190 | + echo 'Search is Powered by Solr!'; |
191 | 191 | echo $queryStr = urldecode( $wgSolrTalker->parseSolrQuery( $query->getQueryString() ) ); |
192 | 192 | |
193 | | - |
194 | 193 | // Get Sort Parameters and add them to the QueryString |
195 | 194 | if ( $query->sort ) { |
196 | 195 | // TODO: Der Inhalt von Sort muss genau der Name eines der Felder von Solr sein |
— | — | @@ -197,25 +196,21 @@ |
198 | 197 | // Benötigt um Festzustellen welches Feld gemeint ist bzw. welche _XYZ Endung |
199 | 198 | // an dem Ende des Feldes angehängt wurde. |
200 | 199 | // |
201 | | - |
202 | | - |
203 | 200 | $sort = $wgSolrTalker->findField( $query->params['sort'], $query->params['order'] ); |
204 | 201 | $queryStr .= '&sort%3D' . $sort . '+' . trim( $query->params['order'] ); |
205 | 202 | // $queryStr = $queryStr . '&sort=' . trim($sort . '+' . trim($query->params['order'])); |
206 | 203 | // TODO: Mehrer Sort parameter auslesen wenn sie vorhanden sind. |
207 | | - } |
208 | | -// else { |
| 204 | + } //else { |
209 | 205 | // $queryStr = $queryStr . '&sort=pagetitle'; |
210 | 206 | // } |
211 | 207 | |
212 | 208 | // TODO: Prüfen wieso nur 1 Ergebniss ausgegeben wird |
213 | 209 | echo 'Query Limit:' . $query->getLimit(); |
214 | 210 | |
215 | | - echo ( "SEARCHRESULT: " . $xml = $wgSolrTalker->solrQuery( $queryStr, $query->getOffset(), $query->getLimit() ) ); |
216 | | - echo( "<br/>" ); |
217 | | - // TODO: Move this Code to parseSolrResult |
| 211 | + echo ( 'SEARCHRESULT: ' . $xml = $wgSolrTalker->solrQuery( $queryStr, $query->getOffset(), $query->getLimit() ) ); |
| 212 | + echo '<br/>'; |
| 213 | + // TODO: Move this code to parseSolrResult |
218 | 214 | $numFound = $xml->result['numFound']; |
219 | | - // print_r('1: ' . $xml->{"result"}); |
220 | 215 | foreach ( $xml->result->doc as $doc ) { |
221 | 216 | foreach ( $doc->str as $field ) { |
222 | 217 | switch ( $field['name'] ) { |
— | — | @@ -230,7 +225,7 @@ |
231 | 226 | break; |
232 | 227 | } |
233 | 228 | } |
234 | | - // Multivalue Felder |
| 229 | + // Multivalue fields |
235 | 230 | foreach ( $doc->arr as $field ) { |
236 | 231 | switch ( $field['name'] ) { |
237 | 232 | case 'dbkey': |
— | — | @@ -250,9 +245,9 @@ |
251 | 246 | $results[] = new SMWDIWikiPage( $dbkey, $namespace, $interwiki ); |
252 | 247 | } |
253 | 248 | |
254 | | - // Do we have more Results ? |
| 249 | + // Do we have more results? |
255 | 250 | $more = false; |
256 | | - // TODO: Does this Work ? |
| 251 | + // TODO: Does this work? |
257 | 252 | echo 'Number of Records: ' . $numFound; |
258 | 253 | if ( $numFound > 10 ) { |
259 | 254 | $more = true; |
— | — | @@ -342,9 +337,7 @@ |
343 | 338 | * @param boolean $verbose |
344 | 339 | */ |
345 | 340 | public function setup( $verbose = true ) { |
346 | | - |
347 | 341 | // TODO: Setup data structures on the the Solr server, if necessary |
348 | | - |
349 | 342 | return self::getBaseStore()->setup( $verbose ); |
350 | 343 | } |
351 | 344 | |
— | — | @@ -390,9 +383,7 @@ |
391 | 384 | * @return decimal between 0 and 1 to indicate the overall progress of the refreshing |
392 | 385 | */ |
393 | 386 | public function refreshData( &$index, $count, $namespaces = false, $usejobs = true ) { |
394 | | - |
395 | 387 | // TODO: Do we need to do something here for Solr? Can we do something? |
396 | | - |
397 | 388 | return self::getBaseStore()->refreshData( $index, $count, $namespaces, $usejobs ); |
398 | 389 | } |
399 | 390 | |