r112880 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112879‎ | r112880 | r112881 >
Date:12:19, 2 March 2012
Author:schuellersa
Status:deferred
Tags:
Comment:
some Style Fixes
and percent fix
Modified paths:
  • /trunk/extensions/SolrStore/SolrTalker.php (modified) (history)
  • /trunk/extensions/SolrStore/SpecialSolrSearch.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SolrStore/SolrTalker.php
@@ -5,7 +5,7 @@
66 *
77 * @ingroup SolrStore
88 * @file
9 - * @author Simon Bachenberg
 9+ * @author Simon Bachenberg, Sascha Schueller
1010 */
1111
1212 /**
@@ -91,13 +91,13 @@
9292 $stop = false;
9393
9494 foreach ( $xml->lst as $item ) {
95 - if ( $item['name'] == 'fields' ) {
 95+ if ( $item[ 'name' ] == 'fields' ) {
9696 foreach ( $item->lst as $field ) {
9797 if ( count( $field ) > 2 ) {
98 - $dynamicBase = substr( $field->str[2], 1 ); // Get the dynamic base of the field eg. "*_dtmax"
99 - $newField = str_replace( $dynamicBase, '', $field['name'] ); // Get the field name without the dynamicbase
 98+ $dynamicBase = substr( $field->str[ 2 ], 1 ); // Get the dynamic base of the field eg. "*_dtmax"
 99+ $newField = str_replace( $dynamicBase, '', $field[ 'name' ] ); // Get the field name without the dynamicbase
100100 if ( strcasecmp( str_replace( ' ', '_', $newField ), $searchField ) == 0 ) { // Replace all spaces with underscore for better matching
101 - $result = trim( $field['name'] );
 101+ $result = trim( $field[ 'name' ] );
102102 if ( stripos( $dynamicBase, 'max' ) && stripos( $sort, 'desc' ) ) {
103103 // For descending sorting use the MaX value field
104104 continue 2; // we got the right field, stop it!
@@ -107,12 +107,12 @@
108108 } elseif ( !stripos( $dynamicBase, 'min' ) && !stripos( $dynamicBase, 'max' ) ) {
109109 continue 2; // we got the right field, stop it!
110110 }
111 - } elseif ( strcasecmp( str_replace( ' ', '_', $field['name'] ), $searchField ) == 0 ) { // Replace all spaces with underscore for better matching
 111+ } elseif ( strcasecmp( str_replace( ' ', '_', $field[ 'name' ] ), $searchField ) == 0 ) { // Replace all spaces with underscore for better matching
112112 $result = trim( $searchField );
113113 }
114114 } else {
115 - if ( strcasecmp( trim( $field['name'] ), trim( $searchField ) ) == 0 ) {
116 - $result = trim( $field['name'] );
 115+ if ( strcasecmp( trim( $field[ 'name' ] ), trim( $searchField ) ) == 0 ) {
 116+ $result = trim( $field[ 'name' ] );
117117 }
118118 }
119119 }
@@ -135,19 +135,22 @@
136136 foreach ( $queryParts as $value ) {
137137 if ( strpos( $value, ':' ) !== false ) { // Value conatins a ":" ?
138138 $parts = explode( ':', $value ); // Split the query part in key (parts[0]) and value (parts[1])
139 - $solrField = $this->findField( $parts[0] ); // Search for a Solr field for the key
 139+ $solrField = $this->findField( $parts[ 0 ] ); // Search for a Solr field for the key
140140 //If we have a Wildcard Search transform Query to Lowercase for a Better Matching.
141141 //Because on wildcard and fuzzy searches, no text analysis is performed on the search word
142142 //and no Analyseres get used
143 - if ( strpos( $parts[1], '*' ) !== false ) {
144 - $parts[1] = strtolower( $parts[1] );
 143+ if ( strpos( $parts[ 1 ], '*' ) !== false ) {
 144+ $parts[ 1 ] = strtolower( $parts[ 1 ] );
 145+ //If we got an "AND" or an "OR" we have to write them uppercase
 146+ $parts[ 1 ] = str_replace( ' and ', ' AND ', $parts[ 1 ] );
 147+ $parts[ 1 ] = str_replace( ' or ', ' OR ', $parts[ 1 ] );
145148 }
146149
147150 //If we have a solrField Match add a ':' (its the Lucene equivalent of '=' )
148151 if ( $solrField ) {
149 - $queryStr = $queryStr . ' ' . $solrField . ':' . $parts[1];
 152+ $queryStr = $queryStr . ' ' . $solrField . ':' . $parts[ 1 ];
150153 } else {
151 - $queryStr = $queryStr . ' ' . $parts[0] . ' ' . $parts[1];
 154+ $queryStr = $queryStr . ' ' . $parts[ 0 ] . ' ' . $parts[ 1 ];
152155 }
153156 } else {
154157 $queryStr = $queryStr . ' ' . $value;
@@ -174,8 +177,8 @@
175178 foreach ( $queryParts as $part ) {
176179 if ( stripos( $part, '::' ) ) {
177180 $parts = explode( '::', $part ); // Split the query part in key (parts[0]) and value (parts[1])
178 - $parts[0] = $this->findField( $parts[0] ); // Search for a Solr field for the key
179 - $queryStr = $queryStr . ' ' . $parts[0] . ':' . $parts[1]; // Build query string
 181+ $parts[ 0 ] = $this->findField( $parts[ 0 ] ); // Search for a Solr field for the key
 182+ $queryStr = $queryStr . ' ' . $parts[ 0 ] . ':' . $parts[ 1 ]; // Build query string
180183 } elseif ( stripos( $part, ':' ) ) {
181184 $queryStr = $queryStr . ' category' . substr( $part, stripos( $part, ':' ) );
182185 } else {
@@ -218,7 +221,7 @@
219222 $ch = curl_init();
220223
221224 $url = str_replace( ' ', '+', $url );
222 - if ($wgSolrDebug){
 225+ if ( $wgSolrDebug ) {
223226 echo $url;
224227 }
225228 curl_setopt( $ch, CURLOPT_URL, $url );
Index: trunk/extensions/SolrStore/SpecialSolrSearch.php
@@ -6,7 +6,7 @@
77 * This is the SpecialPage, displaying the SearchSets and Results
88 *
99 * @defgroup SolrStore
10 - * @author Simon Bachenberg
 10+ * @author Simon Bachenberg, Sascha Schueller
1111 */
1212 class SpecialSolrSearch extends SpecialPage {
1313
@@ -143,7 +143,7 @@
144144
145145 if ( !empty( $query ) ) {
146146 //Add the Extra query string plus a space to the end of the query
147 - $query .=' '.trim($fieldSet->getQuery());
 147+ $query .=' ' . trim( $fieldSet->getQuery() );
148148 }
149149 // TODO: More Exception Handling for Format Exceptions
150150 try {
@@ -447,7 +447,7 @@
448448 // Search engine doesn't report scoring info
449449 $score = '';
450450 } else {
451 - $percent = sprintf( '%2.1f', $result->getScore() * 100 );
 451+ $percent = sprintf( '%2.1f', $result->getScore() * 10 ); // * 100
452452 $score = wfMsg( 'search-result-score', $wgLang->formatNum( $percent ) ) . ' - ';
453453 }
454454

Status & tagging log