r107212 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107211‎ | r107212 | r107213 >
Date:16:53, 24 December 2011
Author:ashley
Status:ok (Comments)
Tags:
Comment:
SolrStore:
*various coding style related things
*documentation tweaks
*dropped some unused variables
*marked some functions marked as @public as such and removed the doxygen comment
*$fname = 'SomeHardcodedName' --> __METHOD__
*in SolrTalker::parseSolrQuery(), changed split() to explode() because split() is deprecated as of PHP 5.3 (IIRC)
Modified paths:
  • /trunk/extensions/SolrStore/SolrConnectorStore.php (modified) (history)
  • /trunk/extensions/SolrStore/SolrDoc.php (modified) (history)
  • /trunk/extensions/SolrStore/SolrSearch.php (modified) (history)
  • /trunk/extensions/SolrStore/SolrTalker.php (modified) (history)
  • /trunk/extensions/SolrStore/SpecialSolrSearch.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SolrStore/SolrTalker.php
@@ -14,12 +14,12 @@
1515 */
1616 class SolrTalker {
1717
18 - private $header = array( "Content-type:text/xml; charset=utf-8" );
 18+ private $header = array( 'Content-type:text/xml; charset=utf-8' );
1919 private $schema;
2020
2121 /**
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
2424 *
2525 * @return type $xml schema
2626 */
@@ -37,7 +37,7 @@
3838 }
3939
4040 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
4242 $query = str_replace( '"', '%22', trim( $query ) );
4343 $query = str_replace( ' ', '+', $query );
4444 $query = str_replace( 'ü', '%FC', $query );
@@ -53,14 +53,14 @@
5454 * Perform a SolrSearch
5555 *
5656 * @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
6060 * @return type $xml - Solr Result as XML
61 - *
6261 */
6362 public function solrQuery( $query, $start, $end, $highlight = false, $score = false ) {
6463 global $wgSolrUrl;
 64+
6565 $query = trim( $query );
6666 if ( empty( $query ) ) {
6767 $query = '*';
@@ -72,6 +72,7 @@
7373 if ( $score ) {
7474 $url .= '&fl=*%2Cscore';
7575 }
 76+
7677 return $this->solrSend( $url );
7778 }
7879
@@ -79,13 +80,13 @@
8081 * Find the real name of the Field in the SOlr schema
8182 *
8283 * @param type $searchField
83 - * @param type $sort = ASC or DESC
 84+ * @param $sort String: ASC or DESC
8485 * @return type Name of the Field you are searching for
8586 */
8687 public function findField( $searchField, $sort = 'ASC' ) {
8788 $xml = $this->getSchema();
8889 // $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
9091 $result = false;
9192 $stop = false;
9293
@@ -94,17 +95,17 @@
9596 if ( $item['name'] == 'fields' ) {
9697 foreach ( $item->lst as $field ) {
9798 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
101102 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!
107108 }
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
109110 $result = trim( $searchField );
110111 }
111112 } else {
@@ -119,7 +120,7 @@
120121 }
121122
122123 /**
123 - * Check the Query for existing fields
 124+ * Check the query for existing fields
124125 *
125126 * @param type $queryStr - Wiki QueryString
126127 * @return type $queryStr - Solr QueryString
@@ -127,12 +128,12 @@
128129 public function queryChecker( $queryStr ) {
129130 $queryStr = str_replace( '=', ':', $queryStr ); // Now you can use = insted : for querying Fields
130131 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
132133 $queryStr = '';
133134 foreach ( $queryParts as $value ) {
134135 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
137138 if ( $solrField ) {
138139 $queryStr = $queryStr . ' ' . $solrField . ':' . $parts[1];
139140 } else {
@@ -148,7 +149,7 @@
149150 }
150151
151152 /**
152 - * Transform a Wiki Query to a Solr Query
 153+ * Transform a wiki query to a Solr query
153154 * TODO: Do more Wiki2Solr transformation
154155 *
155156 * @param type $queryStr - Wiki QueryString
@@ -156,15 +157,15 @@
157158 */
158159 public function parseSolrQuery( $queryStr ) {
159160 // TODO: Parse the QueryString to make it work in Solr
160 - $queryParts = explode( "[[", $queryStr );
 161+ $queryParts = explode( '[[', $queryStr );
161162
162163 // Clean the queryStr
163164 $queryStr = '';
164165 foreach ( $queryParts as $part ) {
165166 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
169170 } elseif ( stripos( $part, ':' ) ) {
170171 $queryStr = $queryStr . ' category' . substr( $part, stripos( $part, ':' ) );
171172 } else {
@@ -196,7 +197,7 @@
197198 }
198199
199200 /**
200 - * Private Function for interactinig with Solr.
 201+ * Private function for interacting with Solr.
201202 *
202203 * @param type $url
203204 * @param type $xmlcontent
@@ -230,15 +231,12 @@
231232
232233 // if the request was successful
233234 if ( $httpCode == 200 ) {
234 -
235235 try {
236236 $xml = new SimpleXMLElement( $data );
237237 } catch ( Exception $exc ) {
238238 throw new MWException( $exc->getMessage() );
239239 }
240 -
241240 } else { // some error occurred
242 -
243241 // have to scrape the error message from the returned HTML
244242 $xml = new DOMDocument;
245243 $xml->loadHTML( $data );
@@ -259,8 +257,8 @@
260258 * @param SolrDoc $file
261259 */
262260 public function addDoc( SolrDoc $file ) {
263 - $filekopf = "<add><doc>";
264 - $filefuss = "</doc></add>";
 261+ $filekopf = '<add><doc>';
 262+ $filefuss = '</doc></add>';
265263 $xmlcontent = $filekopf . $file->printFields() . $filefuss;
266264 return $this->solrAdd( $xmlcontent );
267265 }
@@ -271,8 +269,8 @@
272270 * @return type $xml - Response from Solr
273271 */
274272 public function deleteDocId( $id ) {
275 - $filekopf = "<delte><id>";
276 - $filefuss = "</id></delte>";
 273+ $filekopf = '<delte><id>';
 274+ $filefuss = '</id></delte>';
277275 $xmlcontent = $filekopf . $id . $filefuss;
278276 return $this->solrAdd( $xmlcontent );
279277 }
@@ -283,14 +281,14 @@
284282 * @return type $xml - Response from Solr
285283 */
286284 public function deleteDocQuery( $query ) {
287 - $filekopf = "<delte><query>";
288 - $filefuss = "</query></delte>";
 285+ $filekopf = '<delte><query>';
 286+ $filefuss = '</query></delte>';
289287 $xmlcontent = $filekopf . $query . $filefuss;
290288 return $this->solrAdd( $xmlcontent );
291289 }
292290
293291 /**
294 - * DELETE ALL DOCS FROM SOLR INDEX!!!
 292+ * DELETE ALL DOCS FROM SOLR INDEX!
295293 * @return type $xml - Response from Solr
296294 */
297295 public function deleteAllDocs() {
@@ -299,18 +297,19 @@
300298 }
301299
302300 /**
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
304303 *
305304 * @param SMWSemanticData $data
306305 */
307306 public function parseSemanticData( SMWSemanticData $data ) {
308 - $solritem = new SolrDoc ();
 307+ $solritem = new SolrDoc();
309308
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() );
315314
316315 foreach ( $data->getProperties() as $property ) {
317316 if ( ( $property->getKey() == '_SKEY' ) || ( $property->getKey() == '_REDI' ) ) {
@@ -325,71 +324,71 @@
326325 }
327326 switch ( $di->getDIType() ) {
328327 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;
331330 break;
332331
333332 case 1:
334 -// /// Data item ID for SMWDINumber
335 -// const TYPE_NUMBER = 1;
 333+ // /// Data item ID for SMWDINumber
 334+ // const TYPE_NUMBER = 1;
336335 $solritem->addField( $propertyName . '_i', $di->getNumber() );
337336 $solritem->addSortField( $propertyName . '_i', $di->getNumber() );
338337 break;
339338
340339 case 2:
341 -// /// Data item ID for SMWDIString
342 -// const TYPE_STRING = 2;
 340+ // /// Data item ID for SMWDIString
 341+ // const TYPE_STRING = 2;
343342 $solritem->addField( $propertyName . '_t', $di->getString() );
344343 $solritem->addSortField( $propertyName . '_t', $di->getString() );
345344 break;
346345
347346 case 3:
348 -// /// Data item ID for SMWDIBlob
349 -// const TYPE_BLOB = 3;
 347+ // /// Data item ID for SMWDIBlob
 348+ // const TYPE_BLOB = 3;
350349 $solritem->addField( $propertyName . '_t', $di->getString() );
351350 $solritem->addSortField( $propertyName . '_t', $di->getString() );
352351 break;
353352
354353 case 4:
355 -// /// Data item ID for SMWDIBoolean
356 -// const TYPE_BOOLEAN = 4;
 354+ // /// Data item ID for SMWDIBoolean
 355+ // const TYPE_BOOLEAN = 4;
357356 $solritem->addField( $propertyName . '_b', $di->getBoolean() );
358357 $solritem->addSortField( $propertyName . '_b', $di->getBoolean() );
359358 break;
360359
361360 case 5:
362 -// /// Data item ID for SMWDIUri
363 -// const TYPE_URI = 5;
 361+ // /// Data item ID for SMWDIUri
 362+ // const TYPE_URI = 5;
364363 $solritem->addField( $propertyName . '_t', $di->getURI() );
365364 $solritem->addSortField( $propertyName . '_t', $di->getURI() );
366365 break;
367366
368367 case 6:
369 -// /// Data item ID for SMWDITimePoint
370 -// const TYPE_TIME = 6;
 368+ // /// Data item ID for SMWDITimePoint
 369+ // const TYPE_TIME = 6;
371370 $date = $di->getYear() . '-' . $di->getMonth() . '-' . $di->getDay() . 'T' . $di->getHour() . ':' . $di->getMinute() . ':' . $di->getSecond() . 'Z';
372371 $solritem->addField( $propertyName . '_dt', $date );
373372 $solritem->addSortField( $propertyName . '_dt', $date );
374373 break;
375374
376375 case 7:
377 -// /// Data item ID for SMWDIGeoCoord
378 -// const TYPE_GEO = 7;
 376+ // /// Data item ID for SMWDIGeoCoord
 377+ // const TYPE_GEO = 7;
379378 // TODO: Implement range Search in SOLR
380379 $solritem->addField( $propertyName . '_lat', $di->getLatitude() );
381380 $solritem->addField( $propertyName . '_lng', $di->getLongitude() );
382381 break;
383382
384383 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() . ' : ';
389388 break;
390389
391390 case 9:
392 -// /// Data item ID for SMWDIWikiPage
393 -// const TYPE_WIKIPAGE = 9;
 391+ // /// Data item ID for SMWDIWikiPage
 392+ // const TYPE_WIKIPAGE = 9;
394393 $ns = $di->getNamespace();
395394 if ( $ns == 0 ) {
396395 $solritem->addField( $propertyName . '_s', $di->getTitle() );
@@ -400,21 +399,21 @@
401400 break;
402401
403402 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() . ' : ';
407406 break;
408407
409408 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() . ' : ';
413412 break;
414413
415414 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() . ' : ';
419418 break;
420419 default:
421420 break;
Index: trunk/extensions/SolrStore/SolrDoc.php
@@ -14,34 +14,35 @@
1515 */
1616 class SolrDoc {
1717 private $output;
18 - private $min = array ();
19 - private $max = array ();
 18+ private $min = array();
 19+ private $max = array();
2020
2121 /**
22 - * Add a Field to the SolrDoc
 22+ * Add a field to the SolrDoc
2323 *
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
2626 */
2727 public function addField( $name, $value ) {
28 - $this->output .= '<field name="' . $name . '">' . $value . '</field>' ;
 28+ $this->output .= '<field name="' . $name . '">' . $value . '</field>';
2929 }
3030
3131 /**
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
3334 *
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
3637 */
3738 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] ) ) {
4041 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
4243 $this->min[$name] = $value;
4344 }
4445 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
4647 $this->max[$name] = $value;
4748 }
4849 } else {
@@ -54,10 +55,10 @@
5556 $all = $this->output;
5657
5758 foreach ( $this->min as $name => $value ) {
58 - $all .= '<field name="' . $name . 'min">' . $value . '</field>' ;
 59+ $all .= '<field name="' . $name . 'min">' . $value . '</field>';
5960 }
6061 foreach ( $this->max as $name => $value ) {
61 - $all .= '<field name="' . $name . 'max">' . $value . '</field>' ;
 62+ $all .= '<field name="' . $name . 'max">' . $value . '</field>';
6263 }
6364
6465 return $all;
Index: trunk/extensions/SolrStore/SolrSearch.php
@@ -32,10 +32,16 @@
3333 *
3434 * @param string $term - Raw search term
3535 * @return SolrSearchSet
36 - * @access public
3736 */
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+ );
4046 }
4147
4248 /**
@@ -43,17 +49,16 @@
4450 *
4551 * @param string $term - Raw search term
4652 * @return SolrSearchSet
47 - * @access public
4853 */
49 - function searchTitle( $term ) {
 54+ public function searchTitle( $term ) {
5055 return null;
5156 }
5257
5358 /**
54 - * PrefixSearchBackend override for OpenSearch results
 59+ * PrefixSearchBackend override for OpenSearch results
5560 */
5661 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!
5863 $it = SolrSearchSet::newFromQuery( 'prefix', $search, $ns, $limit, 0 );
5964 $results = array();
6065 if ( $it ) { // $it can be null
@@ -88,38 +93,42 @@
8994 */
9095 function replacePrefixes( $query ) {
9196 global $wgContLang, $wgSolrUseRelated;
92 - $fname = 'SolrSearch::replacePrefixes';
93 - wfProfileIn( $fname );
 97+
 98+ wfProfileIn( __METHOD__ );
9499 $start = 0;
95100 $len = 0; // token start pos and length
96101 $rewritten = ''; // rewritten query
97102 $rindex = 0; // point to last rewritten character
98103 $inquotes = false;
99104
100 -// "search everything" keyword
 105+ // "search everything" keyword
101106 $allkeyword = wfMsgForContent( 'searchall' );
102107
103108 $qlen = strlen( $query );
104109
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
106111 if ( strpos( $query, ':' ) === false ) {
107 - wfProfileOut( $fname );
 112+ wfProfileOut( __METHOD__ );
108113 return $query;
109114 }
110115
111 -// check if this is query for related articles
 116+ // check if this is query for related articles
112117 $relatedkey = wfMsgForContent( 'searchrelated' ) . ':';
113118 if ( $wgSolrUseRelated && strncmp( $query, $relatedkey, strlen( $relatedkey ) ) == 0 ) {
114119 $this->related = true;
115 - list( $dummy, $ret ) = explode( ":", $query, 2 );
116 - wfProfileOut( $fname );
 120+ list( $dummy, $ret ) = explode( ':', $query, 2 );
 121+ wfProfileOut( __METHOD__ );
117122 return trim( $ret );
118123 }
119124
120125 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+ );
122131
123 -# add all namespace names w/o spaces
 132+ # add all namespace names w/o spaces
124133 $nsNames = array();
125134 foreach ( $nsNamesRaw as $ns ) {
126135 if ( $ns != '' ) {
@@ -130,7 +139,7 @@
131140
132141 $regexp = implode( '|', array_unique( $nsNames ) );
133142
134 -# rewrite the query by replacing valid namespace names
 143+ # rewrite the query by replacing valid namespace names
135144 $parts = preg_split( '/(")/', $query, -1, PREG_SPLIT_DELIM_CAPTURE );
136145 $inquotes = false;
137146 $rewritten = '';
@@ -141,13 +150,14 @@
142151 } elseif ( $inquotes ) {
143152 $rewritten .= $part;
144153 } else {
145 -# replace namespaces
 154+ # replace namespaces
146155 $r = preg_replace_callback( '/(^|[| :])(' . $regexp . '):/i', array( $this, 'replaceNamespace' ), $part );
147 -# replace to backend all: notation
 156+ # replace to backend all: notation
148157 $rewritten .= str_replace( $allkeyword . ':', 'all:', $r );
149158 }
150159 }
151 - wfProfileOut( $fname );
 160+
 161+ wfProfileOut( __METHOD__ );
152162 return $rewritten;
153163 }
154164
@@ -155,10 +165,11 @@
156166 function replaceNamespace( $matches ) {
157167 global $wgContLang;
158168 $inx = $wgContLang->getNsIndex( str_replace( ' ', '_', $matches[2] ) );
159 - if ( $inx === false )
 169+ if ( $inx === false ) {
160170 return $matches[0];
161 - else
 171+ } else {
162172 return $matches[1] . "[$inx]:";
 173+ }
163174 }
164175
165176 function acceptListRedirects() {
@@ -170,9 +181,10 @@
171182 global $wgSolrSearchVersion;
172183
173184 if ( $wgSolrSearchVersion >= 2.1 && $this->prefix != '' ) {
174 -# convert to internal backend prefix notation
 185+ # convert to internal backend prefix notation
175186 $term = $term . ' prefix:' . $this->prefix;
176187 }
 188+
177189 return $term;
178190 }
179191
@@ -203,34 +215,33 @@
204216 $xml = $result;
205217 wfDebug( "Solr line: '$result'\n" );
206218
207 - // Defining Results
 219+ // Defining results
208220
209221 $this->mDate = null;
210222 $score = $xml->float;
211223 $this->mScore = $score;
212224
213 -
214225 // -------------------------------------
215 - // Get The Shit out of da XML
 226+ // Get the shit out of the XML
216227 // -------------------------------------
217228 foreach ( $xml->arr as $doc ) {
218229 switch ( $doc['name'] ) {
219230 case 'text':
220231 $nsText = $doc->str;
221232
222 - $this->mSize = "";
 233+ $this->mSize = '';
223234 $this->mWordCount = count( $doc->str );
224235 $snipmax = 10;
225 - $textsnip = "";
 236+ $textsnip = '';
226237 $textsnipvar = 0;
227238 foreach ( $doc->str as $inner ) {
228239 $textsnipvar++;
229240 if ( $textsnipvar >= 4 && $textsnipvar <= $snipmax ) {
230 - $textsnip .= " " . $inner;
 241+ $textsnip .= ' ' . $inner;
231242 }
232243 $this->mSize = $this->mSize + strlen( $inner );
233244 }
234 - $textsnip .= "...";
 245+ $textsnip .= '...';
235246 $this->mSize = ( $this->mSize / 3 );
236247 // $this->mSize=$size;
237248 break;
@@ -253,6 +264,7 @@
254265 break;
255266 }
256267 }
 268+
257269 foreach ( $xml->int as $doci ) {
258270 switch ( $doci['name'] ) {
259271 case 'namespace':
@@ -262,29 +274,30 @@
263275 }
264276
265277 $title = urldecode( $title );
266 - if ( !isset( $nsText ) )
 278+ if ( !isset( $nsText ) ) {
267279 $nsText = $wgContLang->getNsText( $namespace );
268 - else
 280+ } else {
269281 $nsText = urldecode( $nsText );
 282+ }
270283
271284 // make title
272285 $this->mTitle = Title::makeTitle( $namespace, $title );
273286
274 - // HIGHLIHT
275 - // <em> & </em> Fix to <b> // if not, no highlighting !!
 287+ // HIGHLIGHT
 288+ // <em> & </em> Fix to <b> // if not, no highlighting!
276289 // TITLE (LINK)
277290 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 );
280293 } else {
281294 $this->mHighlightTitle = '';
282295 }
283 - // TEXT (under Link)
 296+ // TEXT (under link)
284297 // $this->mHighlightText=$xml->highlight->title;
285298 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 .= '...';
289302 } else {// $this->mHighlightText=textsnip;
290303 if ( isset( $_REQUEST['search'] ) != '' && isset( $textsnip ) != '' ) {
291304 if ( strpos( strtolower( $textsnip ), strtolower( $_REQUEST['search'] ) ) ) {
@@ -292,7 +305,7 @@
293306 $pos1 = strpos( strtolower( $textsnip ), strtolower( $_REQUEST['search'] ) );
294307 $tmpa = substr( $textsnip, 0, $pos1 );
295308 $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;
297310 // str_replace($_REQUEST['search'],"<b>".$_REQUEST['search']."</b>",$textsnip);
298311 } else {
299312 $this->mHighlightText = $textsnip;
@@ -316,17 +329,19 @@
317330 * @return array (highlighted, unmodified text)
318331 */
319332 function extractSnippet( $lines, $nsText, $type, $useFinalSeparator = false ) {
320 - if ( !array_key_exists( $type, $lines ) )
 333+ if ( !array_key_exists( $type, $lines ) ) {
321334 return array( null, null );
322 - $ret = "";
 335+ }
 336+ $ret = '';
323337 $original = null;
324338 foreach ( $lines[$type] as $h ) {
325339 list( $s, $o ) = $this->extractSnippetLine( $h, $useFinalSeparator );
326340 $ret .= $s;
327341 $original = $o;
328342 }
329 - if ( $nsText != '' )
 343+ if ( $nsText != '' ) {
330344 $ret = $nsText . ':' . $ret;
 345+ }
331346 return array( $ret, $original );
332347 }
333348
@@ -339,41 +354,44 @@
340355 * @return array(snippet,unmodified text)
341356 */
342357 function extractSnippetLine( $line, $useFinalSeparator ) {
343 - $parts = explode( " ", $line );
 358+ $parts = explode( ' ', $line );
344359 if ( count( $parts ) != 4 && count( $parts ) != 5 ) {
345360 wfDebug( "Bad result line:" . $line . "\n" );
346 - return "";
 361+ return '';
347362 }
348363 $splits = $this->stripBracketsSplit( $parts[0] );
349364 $highlight = $this->stripBracketsSplit( $parts[1] );
350365 $suffix = urldecode( $this->stripBrackets( $parts[2] ) );
351366 $text = urldecode( $parts[3] );
352367 $original = null;
353 - if ( count( $parts ) > 4 )
 368+ if ( count( $parts ) > 4 ) {
354369 $original = urldecode( $parts[4] );
 370+ }
355371
356372 $splits[] = strlen( $text );
357373 $start = 0;
358 - $snippet = "";
 374+ $snippet = '';
359375 $hi = 0;
360376 $ellipsis = wfMsgForContent( 'ellipsis' );
361377
362378 foreach ( $splits as $sp ) {
363379 $sp = intval( $sp );
364 -// highlight words!
 380+ // highlight words!
365381 while ( $hi < count( $highlight ) && intval( $highlight[$hi] ) < $sp ) {
366382 $s = intval( $highlight[$hi] );
367383 $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>';
369386 $start = $e;
370387 $hi += 2;
371388 }
372 -// copy till split point
 389+ // copy till split point
373390 $snippet .= substr( $text, $start, $sp - $start );
374 - if ( $sp == strlen( $text ) && $suffix != '' )
 391+ if ( $sp == strlen( $text ) && $suffix != '' ) {
375392 $snippet .= $suffix;
376 - else if ( $useFinalSeparator )
377 - $snippet .= " <b>" . $ellipsis . "</b> ";
 393+ } elseif ( $useFinalSeparator ) {
 394+ $snippet .= ' <b>' . $ellipsis . '</b> ';
 395+ }
378396
379397 $start = $sp;
380398 }
@@ -384,8 +402,9 @@
385403 * @access private
386404 */
387405 function stripBrackets( $str ) {
388 - if ( $str == '[]' )
 406+ if ( $str == '[]' ) {
389407 return '';
 408+ }
390409 return substr( $str, 1, strlen( $str ) - 2 );
391410 }
392411
@@ -395,10 +414,11 @@
396415 */
397416 function stripBracketsSplit( $str ) {
398417 $strip = $this->stripBrackets( $str );
399 - if ( $strip == '' )
 418+ if ( $strip == '' ) {
400419 return array();
401 - else
402 - return explode( ",", $strip );
 420+ } else {
 421+ return explode( ',', $strip );
 422+ }
403423 }
404424
405425 function getTitle() {
@@ -406,22 +426,24 @@
407427 }
408428
409429 function getScore() {
410 - if ( is_null( $this->mScore ) )
 430+ if ( is_null( $this->mScore ) ) {
411431 return null; // Solr scores are meaningless to the user...
 432+ }
412433
413 -// echo($this->mScore." ");
414434 return floatval( $this->mScore );
415435 }
416436
417437 function getTitleSnippet( $terms ) {
418 - if ( is_null( $this->mHighlightTitle ) )
 438+ if ( is_null( $this->mHighlightTitle ) ) {
419439 return '';
 440+ }
420441 return $this->mHighlightTitle;
421442 }
422443
423444 function getTextSnippet( $terms ) {
424 - if ( is_null( $this->mHighlightText ) )
 445+ if ( is_null( $this->mHighlightText ) ) {
425446 return parent::getTextSnippet( $terms );
 447+ }
426448 return $this->mHighlightText;
427449 }
428450
@@ -439,14 +461,16 @@
440462 }
441463
442464 function getSectionSnippet() {
443 - if ( is_null( $this->mHighlightSection ) )
 465+ if ( is_null( $this->mHighlightSection ) ) {
444466 return null;
 467+ }
445468 return $this->mHighlightSection;
446469 }
447470
448471 function getSectionTitle() {
449 - if ( is_null( $this->mSectionTitle ) )
 472+ if ( is_null( $this->mSectionTitle ) ) {
450473 return null;
 474+ }
451475 return $this->mSectionTitle;
452476 }
453477
@@ -459,20 +483,23 @@
460484 }
461485
462486 function getTimestamp() {
463 - if ( is_null( $this->mDate ) )
 487+ if ( is_null( $this->mDate ) ) {
464488 return parent::getTimestamp();
 489+ }
465490 return $this->mDate;
466491 }
467492
468493 function getWordCount() {
469 - if ( is_null( $this->mWordCount ) )
 494+ if ( is_null( $this->mWordCount ) ) {
470495 return parent::getWordCount();
 496+ }
471497 return $this->mWordCount;
472498 }
473499
474500 function getByteSize() {
475 - if ( is_null( $this->mSize ) )
 501+ if ( is_null( $this->mSize ) ) {
476502 return parent::getByteSize();
 503+ }
477504 return $this->mSize;
478505 }
479506
@@ -489,22 +516,20 @@
490517 * Contact the MWDaemon search server and return a wrapper
491518 * object with the set of results. Results may be cached.
492519 *
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
498525 * @return array
499 - * @access public
500526 */
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__ );
504529
505530 $wgSolrTalker = new SolrTalker();
506531
507532 $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
509534 $totalHits = $xml->result['numFound'];
510535
511536 $resultLines = array(); ;
@@ -514,14 +539,10 @@
515540 $hli = 0;
516541
517542 foreach ( $xml->result->doc as $doc ) {
518 -
519543 if ( isset( $highl[$hli]->arr ) ) {
520 -
521544 foreach ( $highl[$hli]->arr as $feld ) {
522545 if ( isset( $feld['name'] ) ) {
523 -
524546 switch ( $feld['name'] ) {
525 -
526547 case 'title':
527548 $doc[]->highlight->title = $feld->str;
528549 break;
@@ -536,16 +557,16 @@
537558 $resultLines[] = $doc;
538559 }
539560
540 -
541561 $suggestion = null;
542562 $info = null;
543563 $interwiki = null;
544564
 565+ $resultSet = new SolrSearchSet(
 566+ $method, $query, $resultLines, count( $resultLines ), $totalHits,
 567+ $suggestion, $info, $interwiki
 568+ );
545569
546 - $resultSet = new SolrSearchSet( $method, $query, $resultLines, count( $resultLines ), $totalHits,
547 - $suggestion, $info, $interwiki );
548 -
549 - wfProfileOut( $fname );
 570+ wfProfileOut( __METHOD__ );
550571 return $resultSet;
551572 }
552573
@@ -581,17 +602,19 @@
582603
583604 /** Get suggestions from a suggestion result line */
584605 function parseSuggestion( $suggestion ) {
585 - if ( is_null( $suggestion ) )
 606+ if ( is_null( $suggestion ) ) {
586607 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 );
589612 $sug = urldecode( $sug );
590 - $points = explode( ",", substr( $points, 1, -1 ) );
 613+ $points = explode( ',', substr( $points, 1, -1 ) );
591614 array_unshift( $points, 0 );
592 - $suggestText = "";
 615+ $suggestText = '';
593616 for ( $i = 1; $i < count( $points ); $i += 2 ) {
594617 $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>';
596619 }
597620 $suggestText .= htmlspecialchars( substr( $sug, end( $points ) ) );
598621
@@ -601,19 +624,24 @@
602625
603626 /** replace prefixes like [2]: that are not in phrases */
604627 function replaceGenericPrefixes( $text ) {
605 - $out = "";
 628+ $out = '';
606629 $phrases = explode( '"', $text );
607630 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 ) ) {
610637 $out .= '"' . $phrases[$i + 1] . '"'; // phrase text
 638+ }
611639 }
612640 return $out;
613641 }
614642
615643 function genericPrefixCallback( $matches ) {
616644 global $wgContLang;
617 - return $wgContLang->getFormattedNsText( $matches[1] ) . ":";
 645+ return $wgContLang->getFormattedNsText( $matches[1] ) . ':';
618646 }
619647
620648 function numRows() {
@@ -621,25 +649,26 @@
622650 }
623651
624652 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 );
627655
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.
632660 $regexes = array();
633661 $m = array();
634662 $lc = SearchEngine::legalSearchChars();
635663 if ( preg_match_all( '/([-+<>~]?)(([' . $lc . ']+)(\*?)|"[^"]*")/', $resq, $m, PREG_SET_ORDER ) ) {
636664 foreach ( $m as $terms ) {
637665 if ( !empty( $terms[3] ) ) {
638 -// Match individual terms in result highlighting...
 666+ // Match individual terms in result highlighting...
639667 $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+ }
642671 } else {
643 -// Match the quoted term in result highlighting...
 672+ // Match the quoted term in result highlighting...
644673 $regexp = preg_quote( str_replace( '"', '', $terms[2] ), '/' );
645674 }
646675 $regexes[] = $regexp;
@@ -670,9 +699,8 @@
671700 * settings.
672701 *
673702 * @return int
674 - * @access public
675703 */
676 - function getTotalHits() {
 704+ public function getTotalHits() {
677705 return $this->mTotalHits;
678706 }
679707
@@ -683,9 +711,10 @@
684712 * @return string
685713 */
686714 function getInfo() {
687 - if ( is_null( $this->mInfo ) )
 715+ if ( is_null( $this->mInfo ) ) {
688716 return null;
689 - return "Search results fetched via " . $this->mInfo;
 717+ }
 718+ return 'Search results fetched via ' . $this->mInfo;
690719 }
691720
692721 /**
@@ -702,9 +731,8 @@
703732 * no exact hits. Returns true if there is one on this set.
704733 *
705734 * @return bool
706 - * @access public
707735 */
708 - function hasSuggestion() {
 736+ public function hasSuggestion() {
709737 return is_string( $this->mSuggestionQuery ) && $this->mSuggestionQuery != '';
710738 }
711739
@@ -719,10 +747,9 @@
720748 /**
721749 * Fetches next search result, or false.
722750 * @return SolrResult
723 - * @access public
724751 * @abstract
725752 */
726 - function next() {
 753+ public function next() {
727754 if ( $this->mPos < $this->mResultCount ) {
728755 $this->mPos++;
729756 return new SolrResult( $this->mResults[$this->mPos - 1], $this->mMethod );
Index: trunk/extensions/SolrStore/SpecialSolrSearch.php
@@ -24,7 +24,7 @@
2525 * @param $user User
2626 */
2727 public function __construct() {
28 - parent::__construct( "SolrSearch" );
 28+ parent::__construct( 'SolrSearch' );
2929 global $wgRequest, $wgUser, $wgOut, $wgSolrFields;
3030 $user = $wgUser;
3131 $request = $wgRequest;
@@ -40,16 +40,12 @@
4141 $this->setHeaders();
4242 $SpecialSolrSearch = new SpecialSolrSearch( $wgRequest, $wgUser );
4343
44 - # Get request data from, e.g.
45 - $param = $wgRequest->getText( 'param' );
46 -
4744 foreach ( $wgSolrFields as $set ) {
4845 if ( $par == $set->getName() ) {
4946 $fieldSet = $set;
5047 }
5148 }
52 - # Do stuff
53 - # ...
 49+
5450 // Strip underscores from title parameter; most of the time we'll want
5551 // text form here. But don't strip underscores from actual text params!
5652 $titleParam = str_replace( '_', ' ', $par );
@@ -63,13 +59,13 @@
6460 $firstTimeHere = true;
6561 foreach ( $fieldSet->getFields() as $field ) {
6662 if ( $firstTimeHere ) {
67 - $newLable ['solr' . trim( $field )] = trim( $lable[0] );
 63+ $newLable['solr' . trim( $field )] = trim( $lable[0] );
6864 $firstTimeHere = false;
6965 } else {
70 - $newLable ['solr' . trim( $field )] = trim( next( $lable ) );
 66+ $newLable['solr' . trim( $field )] = trim( next( $lable ) );
7167 }
7268
73 - $newFields ['solr' . trim( $field )] = $wgRequest->getText( 'solr' . trim( $field ) );
 69+ $newFields['solr' . trim( $field )] = $wgRequest->getText( 'solr' . trim( $field ) );
7470 }
7571 $fieldSet->setFields( $newFields );
7672 $fieldSet->setLable( $newLable );
@@ -87,22 +83,21 @@
8884
8985 $sk = $wgUser->getSkin();
9086
91 -
9287 $wgOut->setPageTitle( wfMsg( 'solrstore-searchFieldSets' ) );
9388 $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'solrstore-searchFieldSets-title', 'SolrSearch: Select FieldSet' ) ) );
9489
9590 $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>' );
9994
10095 // TODO: If no SearchSets exist, provide a shot Manual how to create some!
10196 foreach ( $wgSolrFields as $set ) {
10297 $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>" );
10499 }
105 - $wgOut->addHtml( '</ul>' );
106 - $wgOut->addHtml( "</div>" );
 100+ $wgOut->addHTML( '</ul>' );
 101+ $wgOut->addHTML( '</div>' );
107102
108103 wfProfileOut( __METHOD__ );
109104 }
@@ -124,17 +119,16 @@
125120
126121 $t = Title::newFromText( $fieldSet->getName() );
127122
128 - // DO we have Title matches
 123+ // Do we have title matches?
129124 $fields = $fieldSet->getFields();
130125
131 - // BUILD SOLR QUERY STRING FROM DA FIELDS
 126+ // Build Solr query string from the fields
132127 if ( isset( $fields['solrsearch'] ) ) {
133128 $query = $fields['solrsearch'];
134129 } else {
135130 $query = '';
136131 }
137132
138 -
139133 foreach ( $fields as $key => $value ) {
140134 if ( $key != 'solrsearch' && !empty( $value ) ) {
141135 $query = trim( $query ) . ' ' . trim( substr( $key, 4 ) ) . ':' . '(' . ( $value ) . ')';
@@ -147,8 +141,9 @@
148142
149143 $titleMatches = $search->searchTitle( $query );
150144
151 - if ( !( $titleMatches instanceof SearchResultTooMany ) )
 145+ if ( !( $titleMatches instanceof SearchResultTooMany ) ) {
152146 $textMatches = $search->searchText( $query );
 147+ }
153148
154149 // did you mean... suggestions
155150 if ( $textMatches && $textMatches->hasSuggestion() ) {
@@ -161,33 +156,37 @@
162157
163158 $suggestionSnippet = $textMatches->getSuggestionSnippet();
164159
165 - if ( $suggestionSnippet == '' )
 160+ if ( $suggestionSnippet == '' ) {
166161 $suggestionSnippet = null;
 162+ }
167163
168164 $suggestLink = $sk->linkKnown(
169 - $st, $suggestionSnippet, array(), $stParams
 165+ $st, $suggestionSnippet, array(), $stParams
170166 );
171167
172 - $this->didYouMeanHtml = '<div class="searchdidyoumean">' . wfMsg( 'search-suggest', $suggestLink ) . '</div>';
 168+ $this->didYouMeanHtml = '<div class="searchdidyoumean">' .
 169+ wfMsg( 'search-suggest', $suggestLink ) . '</div>';
173170 }
 171+
174172 // start rendering the page
175 - $wgOut->addHtml(
176 - Xml::openElement(
177 - 'form', array(
 173+ $wgOut->addHTML(
 174+ Xml::openElement(
 175+ 'form',
 176+ array(
178177 'id' => 'solrsearch',
179178 'method' => 'get',
180179 'action' => $wgScript
181 - )
182180 )
 181+ )
183182 );
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' )
192191 );
193192
194193 // Sometimes the search engine knows there are too many hits
@@ -226,14 +225,19 @@
227226 // show number of results and current offset
228227 $wgOut->addHTML( $this->formHeader( $query, $num, $totalRes ) );
229228
230 - $wgOut->addHtml( Xml::closeElement( 'form' ) );
231 - $wgOut->addHtml( "<div class='searchresults'>" );
 229+ $wgOut->addHTML( Xml::closeElement( 'form' ) );
 230+ $wgOut->addHTML( "<div class='searchresults'>" );
232231
233232 // prev/next links
234233 if ( $num || $this->offset ) {
235234 // Show the create link ahead
236235 $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
238242 );
239243 // $wgOut->addHTML( "<p class='mw-search-pager-top'>{$prevnext}</p>\n" );
240244 wfRunHooks( 'SpecialSolrSearchResults', array( $fieldSet, &$titleMatches, &$textMatches ) );
@@ -266,7 +270,7 @@
267271 $textMatches->free();
268272 }
269273
270 - $wgOut->addHtml( "</div>" );
 274+ $wgOut->addHTML( '</div>' );
271275
272276 if ( $num || $this->offset ) {
273277 $wgOut->addHTML( "<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
@@ -289,7 +293,8 @@
290294 }
291295 }
292296 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() ) ) );
294299 } else {
295300 // preserve the paragraph for margins etc...
296301 $wgOut->addHtml( '<p></p>' );
@@ -308,7 +313,7 @@
309314 }
310315 $wgOut->setArticleRelated( false );
311316 $wgOut->setRobotPolicy( 'noindex,nofollow' );
312 - // add javascript specific to special:search
 317+ // add JavaScript specific to Special:Search
313318 $wgOut->addModules( 'mediawiki.legacy.search' );
314319 $wgOut->addModules( 'mediawiki.special.search' );
315320 }
@@ -324,13 +329,12 @@
325330
326331 $fieldSets = $wgContLang->convertForSearchResult( $matches->termMatches() );
327332
328 - $out = "";
 333+ $out = '';
329334 $infoLine = $matches->getInfo();
330335 if ( !is_null( $infoLine ) ) {
331336 $out .= "\n<!-- {$infoLine} -->\n";
332337 }
333338 $out .= "<ul class='mw-search-results'>\n";
334 - $xxx = 0;
335339 while ( $result = $matches->next() ) {
336340 $out .= $this->showHit( $result, $fieldSets );
337341 }
@@ -362,8 +366,9 @@
363367
364368 $titleSnippet = $result->getTitleSnippet( $fieldSets );
365369
366 - if ( $titleSnippet == '' )
 370+ if ( $titleSnippet == '' ) {
367371 $titleSnippet = null;
 372+ }
368373
369374 $link_t = clone $t;
370375
@@ -399,28 +404,30 @@
400405 $redirect = '';
401406
402407 if ( !is_null( $redirectTitle ) ) {
403 - if ( $redirectText == '' )
 408+ if ( $redirectText == '' ) {
404409 $redirectText = null;
 410+ }
405411
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>';
409415 }
410416
411417 $section = '';
412418
413419
414420 if ( !is_null( $sectionTitle ) ) {
415 - if ( $sectionText == '' )
 421+ if ( $sectionText == '' ) {
416422 $sectionText = null;
 423+ }
417424
418 - $section = "<span class='searchalttitle'>" .
 425+ $section = '<span class="searchalttitle">' .
419426 wfMsg( 'search-section', $this->sk->linkKnown( $sectionTitle, $sectionText ) ) .
420 - "</span>";
 427+ '</span>';
421428 }
422429
423430 // format text extract
424 - $extract = "<div class='searchresult'>" . $result->getTextSnippet( $fieldSets ) . "</div>";
 431+ $extract = '<div class="searchresult">' . $result->getTextSnippet( $fieldSets ) . '</div>';
425432
426433 // format score
427434 if ( is_null( $result->getScore() ) ) {
@@ -435,11 +442,15 @@
436443 $byteSize = $result->getByteSize();
437444 $wordCount = $result->getWordCount();
438445 $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 ) );
440448
441449 if ( $t->getNamespace() == NS_CATEGORY ) {
442450 $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() ) );
444455 }
445456
446457 $date = $wgLang->timeanddate( $timestamp );
@@ -453,7 +464,7 @@
454465 }
455466
456467 // Include a thumbnail for media files...
457 - // WE HAVE NEVER TESTED THIS HERE!!!
 468+ // WE HAVE NEVER TESTED THIS HERE!
458469 if ( $t->getNamespace() == NS_FILE ) {
459470 $img = wfFindFile( $t );
460471 if ( $img ) {
@@ -464,7 +475,7 @@
465476 // Float doesn't seem to interact well with the bullets.
466477 // Table messes up vertical alignment of the bullets.
467478 // Bullets are therefore disabled (didn't look great anyway).
468 - return "<li>" .
 479+ return '<li>' .
469480 '<table class="searchResultImage">' .
470481 '<tr>' .
471482 '<td width="120" align="center" valign="top">' .
@@ -497,7 +508,13 @@
498509 // Results-info
499510 if ( $resultsShown > 0 ) {
500511 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 )
502519 );
503520 } elseif ( $resultsShown >= $this->limit ) {
504521 $top = wfShowingResults( $this->offset, $this->limit );
@@ -516,7 +533,6 @@
517534 protected function shortDialog( $fieldSet ) {
518535 $searchTitle = SpecialPage::getTitleFor( 'SolrSearch' );
519536
520 -
521537 if ( $fieldSet->getName() != 'search' ) {
522538 $out = Html::hidden( 'title', $searchTitle->getPrefixedText() . '/' . $fieldSet->getName() ) . "\n";
523539 } else {
@@ -534,10 +550,10 @@
535551 }
536552 $out .= '<td>';
537553 $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";
542558 $out .= '</td></tr>';
543559 }
544560 $out .= '<table>';
Index: trunk/extensions/SolrStore/SolrConnectorStore.php
@@ -151,7 +151,6 @@
152152 * $redirid will be 0.
153153 */
154154 public function changeTitle( Title $oldtitle, Title $newtitle, $pageid, $redirid = 0 ) {
155 -
156155 // TODO: Update Solr to reflect a renaming of some article
157156 return self::getBaseStore()->changeTitle( $oldtitle, $newtitle, $pageid, $redirid );
158157 }
@@ -171,9 +170,10 @@
172171 */
173172 public function getQueryResult( SMWQuery $query ) {
174173 // 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
178178 $wgSolrTalker = new SolrTalker();
179179 if ( property_exists( $query, 'params' ) &&
180180 array_key_exists( 'source', $query->params ) &&
@@ -186,10 +186,9 @@
187187
188188 echo( "SOLR query: {$query->getQueryString()}\n" );
189189
190 - echo( "Search is Powered by Solr!" );
 190+ echo 'Search is Powered by Solr!';
191191 echo $queryStr = urldecode( $wgSolrTalker->parseSolrQuery( $query->getQueryString() ) );
192192
193 -
194193 // Get Sort Parameters and add them to the QueryString
195194 if ( $query->sort ) {
196195 // TODO: Der Inhalt von Sort muss genau der Name eines der Felder von Solr sein
@@ -197,25 +196,21 @@
198197 // Benötigt um Festzustellen welches Feld gemeint ist bzw. welche _XYZ Endung
199198 // an dem Ende des Feldes angehängt wurde.
200199 //
201 -
202 -
203200 $sort = $wgSolrTalker->findField( $query->params['sort'], $query->params['order'] );
204201 $queryStr .= '&sort%3D' . $sort . '+' . trim( $query->params['order'] );
205202 // $queryStr = $queryStr . '&sort=' . trim($sort . '+' . trim($query->params['order']));
206203 // TODO: Mehrer Sort parameter auslesen wenn sie vorhanden sind.
207 - }
208 -// else {
 204+ } //else {
209205 // $queryStr = $queryStr . '&sort=pagetitle';
210206 // }
211207
212208 // TODO: Prüfen wieso nur 1 Ergebniss ausgegeben wird
213209 echo 'Query Limit:' . $query->getLimit();
214210
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
218214 $numFound = $xml->result['numFound'];
219 - // print_r('1: ' . $xml->{"result"});
220215 foreach ( $xml->result->doc as $doc ) {
221216 foreach ( $doc->str as $field ) {
222217 switch ( $field['name'] ) {
@@ -230,7 +225,7 @@
231226 break;
232227 }
233228 }
234 - // Multivalue Felder
 229+ // Multivalue fields
235230 foreach ( $doc->arr as $field ) {
236231 switch ( $field['name'] ) {
237232 case 'dbkey':
@@ -250,9 +245,9 @@
251246 $results[] = new SMWDIWikiPage( $dbkey, $namespace, $interwiki );
252247 }
253248
254 - // Do we have more Results ?
 249+ // Do we have more results?
255250 $more = false;
256 - // TODO: Does this Work ?
 251+ // TODO: Does this work?
257252 echo 'Number of Records: ' . $numFound;
258253 if ( $numFound > 10 ) {
259254 $more = true;
@@ -342,9 +337,7 @@
343338 * @param boolean $verbose
344339 */
345340 public function setup( $verbose = true ) {
346 -
347341 // TODO: Setup data structures on the the Solr server, if necessary
348 -
349342 return self::getBaseStore()->setup( $verbose );
350343 }
351344
@@ -390,9 +383,7 @@
391384 * @return decimal between 0 and 1 to indicate the overall progress of the refreshing
392385 */
393386 public function refreshData( &$index, $count, $namespaces = false, $usejobs = true ) {
394 -
395387 // TODO: Do we need to do something here for Solr? Can we do something?
396 -
397388 return self::getBaseStore()->refreshData( $index, $count, $namespaces, $usejobs );
398389 }
399390

Follow-up revisions

RevisionCommit summaryAuthorDate
r108148SolrStore: follow-up to r107212 -- fix typo spotted by Nikerabbit + general g...ashley16:21, 5 January 2012

Comments

#Comment by Nikerabbit (talk | contribs)   10:53, 25 December 2011

There is typo: aproche

Status & tagging log