r109921 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109920‎ | r109921 | r109922 >
Date:11:14, 24 January 2012
Author:sbachenberg
Status:deferred
Tags:
Comment:
Fixed: Error in findField
Modified paths:
  • /trunk/extensions/SolrStore/SolrTalker.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SolrStore/SolrTalker.php
@@ -1,4 +1,5 @@
22 <?php
 3+
34 /**
45 * File holding the SolrTalker class
56 *
@@ -85,12 +86,10 @@
8687 */
8788 public function findField( $searchField, $sort = 'ASC' ) {
8889 $xml = $this->getSchema();
89 - // $searchField = trim($searchField);
9090 $searchField = str_replace( ' ', '_', trim( $searchField ) ); // Trim and replace all spaces with underscore for better matching
9191 $result = false;
9292 $stop = false;
9393
94 - // TODO: Decide on ASC + DESC parameter for Max or Min Sort Field
9594 foreach ( $xml->lst as $item ) {
9695 if ( $item['name'] == 'fields' ) {
9796 foreach ( $item->lst as $field ) {
@@ -98,13 +97,15 @@
9998 $dynamicBase = substr( $field->str[2], 1 ); // Get the dynamic base of the field eg. "*_dtmax"
10099 $newField = str_replace( $dynamicBase, '', $field['name'] ); // Get the field name without the dynamicbase
101100 if ( strcasecmp( str_replace( ' ', '_', $newField ), $searchField ) == 0 ) { // Replace all spaces with underscore for better matching
102 - $result = trim($field['name']);
 101+ $result = trim( $field['name'] );
103102 if ( stripos( $dynamicBase, 'max' ) && stripos( $sort, 'desc' ) ) {
104103 // For descending sorting use the MaX value field
105 - continue 2; // we got the right field, stop it!
 104+ continue 2; // we got the right field, stop it!
106105 } elseif ( stripos( $dynamicBase, 'min' ) && stripos( $sort, 'asc' ) ) {
107106 // For ascending sorting use the MIN value field
108107 continue 2; // we got the right field, stop it!
 108+ } elseif ( !stripos( $dynamicBase, 'min' ) && !stripos( $dynamicBase, 'max' ) ) {
 109+ continue 2; // we got the right field, stop it!
109110 }
110111 } elseif ( strcasecmp( str_replace( ' ', '_', $field['name'] ), $searchField ) == 0 ) { // Replace all spaces with underscore for better matching
111112 $result = trim( $searchField );
@@ -135,14 +136,13 @@
136137 if ( strpos( $value, ':' ) !== false ) { // Value conatins a ":" ?
137138 $parts = explode( ':', $value ); // Split the query part in key (parts[0]) and value (parts[1])
138139 $solrField = $this->findField( $parts[0] ); // Search for a Solr field for the key
139 -
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
143143 if ( strpos( $parts[1], '*' ) !== false ) {
144144 $parts[1] = strtolower( $parts[1] );
145145 }
146 -
 146+
147147 //If we have a solrField Match add a ':' (its the Lucene equivalent of '=' )
148148 if ( $solrField ) {
149149 $queryStr = $queryStr . ' ' . $solrField . ':' . $parts[1];
@@ -334,71 +334,71 @@
335335 }
336336 switch ( $di->getDIType() ) {
337337 case 0:
338 - // /// Data item ID that can be used to indicate that no data item class is appropriate
339 - // const TYPE_NOTYPE = 0;
 338+ // /// Data item ID that can be used to indicate that no data item class is appropriate
 339+ // const TYPE_NOTYPE = 0;
340340 break;
341341
342342 case 1:
343 - // /// Data item ID for SMWDINumber
344 - // const TYPE_NUMBER = 1;
 343+ // /// Data item ID for SMWDINumber
 344+ // const TYPE_NUMBER = 1;
345345 $solritem->addField( $propertyName . '_i', $di->getNumber() );
346346 $solritem->addSortField( $propertyName . '_i', $di->getNumber() );
347347 break;
348348
349349 case 2:
350 - // /// Data item ID for SMWDIString
351 - // const TYPE_STRING = 2;
 350+ // /// Data item ID for SMWDIString
 351+ // const TYPE_STRING = 2;
352352 $solritem->addField( $propertyName . '_t', $di->getString() );
353353 $solritem->addSortField( $propertyName . '_t', $di->getString() );
354354 break;
355355
356356 case 3:
357 - // /// Data item ID for SMWDIBlob
358 - // const TYPE_BLOB = 3;
 357+ // /// Data item ID for SMWDIBlob
 358+ // const TYPE_BLOB = 3;
359359 $solritem->addField( $propertyName . '_t', $di->getString() );
360360 $solritem->addSortField( $propertyName . '_t', $di->getString() );
361361 break;
362362
363363 case 4:
364 - // /// Data item ID for SMWDIBoolean
365 - // const TYPE_BOOLEAN = 4;
 364+ // /// Data item ID for SMWDIBoolean
 365+ // const TYPE_BOOLEAN = 4;
366366 $solritem->addField( $propertyName . '_b', $di->getBoolean() );
367367 $solritem->addSortField( $propertyName . '_b', $di->getBoolean() );
368368 break;
369369
370370 case 5:
371 - // /// Data item ID for SMWDIUri
372 - // const TYPE_URI = 5;
 371+ // /// Data item ID for SMWDIUri
 372+ // const TYPE_URI = 5;
373373 $solritem->addField( $propertyName . '_t', $di->getURI() );
374374 $solritem->addSortField( $propertyName . '_t', $di->getURI() );
375375 break;
376376
377377 case 6:
378 - // /// Data item ID for SMWDITimePoint
379 - // const TYPE_TIME = 6;
 378+ // /// Data item ID for SMWDITimePoint
 379+ // const TYPE_TIME = 6;
380380 $date = $di->getYear() . '-' . $di->getMonth() . '-' . $di->getDay() . 'T' . $di->getHour() . ':' . $di->getMinute() . ':' . $di->getSecond() . 'Z';
381381 $solritem->addField( $propertyName . '_dt', $date );
382382 $solritem->addSortField( $propertyName . '_dt', $date );
383383 break;
384384
385385 case 7:
386 - // /// Data item ID for SMWDIGeoCoord
387 - // const TYPE_GEO = 7;
 386+ // /// Data item ID for SMWDIGeoCoord
 387+ // const TYPE_GEO = 7;
388388 // TODO: Implement range Search in SOLR
389389 $solritem->addField( $propertyName . '_lat', $di->getLatitude() );
390390 $solritem->addField( $propertyName . '_lng', $di->getLongitude() );
391391 break;
392392
393393 case 8:
394 - // /// Data item ID for SMWDIContainer
395 - // const TYPE_CONTAINER = 8
 394+ // /// Data item ID for SMWDIContainer
 395+ // const TYPE_CONTAINER = 8
396396 // TODO: What the hell is this used for?
397397 $data->getSubject()->getTitle()->getText() . ' : ';
398398 break;
399399
400400 case 9:
401 - // /// Data item ID for SMWDIWikiPage
402 - // const TYPE_WIKIPAGE = 9;
 401+ // /// Data item ID for SMWDIWikiPage
 402+ // const TYPE_WIKIPAGE = 9;
403403 $ns = $di->getNamespace();
404404 if ( $ns == 0 ) {
405405 $solritem->addField( $propertyName . '_s', $di->getTitle() );
@@ -409,20 +409,20 @@
410410 break;
411411
412412 case 10:
413 - // /// Data item ID for SMWDIConcept
414 - // const TYPE_CONCEPT = 10;
 413+ // /// Data item ID for SMWDIConcept
 414+ // const TYPE_CONCEPT = 10;
415415 $data->getSubject()->getTitle()->getText() . ' : ';
416416 break;
417417
418418 case 11:
419 - // /// Data item ID for SMWDIProperty
420 - // const TYPE_PROPERTY = 11;
 419+ // /// Data item ID for SMWDIProperty
 420+ // const TYPE_PROPERTY = 11;
421421 $data->getSubject()->getTitle()->getText() . ' : ';
422422 break;
423423
424424 case 12:
425 - // /// Data item ID for SMWDIError
426 - // const TYPE_ERROR = 12;
 425+ // /// Data item ID for SMWDIError
 426+ // const TYPE_ERROR = 12;
427427 $data->getSubject()->getTitle()->getText() . ' : ';
428428 break;
429429 default:

Status & tagging log