Index: trunk/extensions/SolrStore/SolrTalker.php |
— | — | @@ -1,4 +1,5 @@ |
2 | 2 | <?php |
| 3 | + |
3 | 4 | /** |
4 | 5 | * File holding the SolrTalker class |
5 | 6 | * |
— | — | @@ -85,12 +86,10 @@ |
86 | 87 | */ |
87 | 88 | public function findField( $searchField, $sort = 'ASC' ) { |
88 | 89 | $xml = $this->getSchema(); |
89 | | - // $searchField = trim($searchField); |
90 | 90 | $searchField = str_replace( ' ', '_', trim( $searchField ) ); // Trim and replace all spaces with underscore for better matching |
91 | 91 | $result = false; |
92 | 92 | $stop = false; |
93 | 93 | |
94 | | - // TODO: Decide on ASC + DESC parameter for Max or Min Sort Field |
95 | 94 | foreach ( $xml->lst as $item ) { |
96 | 95 | if ( $item['name'] == 'fields' ) { |
97 | 96 | foreach ( $item->lst as $field ) { |
— | — | @@ -98,13 +97,15 @@ |
99 | 98 | $dynamicBase = substr( $field->str[2], 1 ); // Get the dynamic base of the field eg. "*_dtmax" |
100 | 99 | $newField = str_replace( $dynamicBase, '', $field['name'] ); // Get the field name without the dynamicbase |
101 | 100 | 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'] ); |
103 | 102 | if ( stripos( $dynamicBase, 'max' ) && stripos( $sort, 'desc' ) ) { |
104 | 103 | // 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! |
106 | 105 | } elseif ( stripos( $dynamicBase, 'min' ) && stripos( $sort, 'asc' ) ) { |
107 | 106 | // For ascending sorting use the MIN value field |
108 | 107 | 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! |
109 | 110 | } |
110 | 111 | } elseif ( strcasecmp( str_replace( ' ', '_', $field['name'] ), $searchField ) == 0 ) { // Replace all spaces with underscore for better matching |
111 | 112 | $result = trim( $searchField ); |
— | — | @@ -135,14 +136,13 @@ |
136 | 137 | if ( strpos( $value, ':' ) !== false ) { // Value conatins a ":" ? |
137 | 138 | $parts = explode( ':', $value ); // Split the query part in key (parts[0]) and value (parts[1]) |
138 | 139 | $solrField = $this->findField( $parts[0] ); // Search for a Solr field for the key |
139 | | - |
140 | 140 | //If we have a Wildcard Search transform Query to Lowercase for a Better Matching. |
141 | 141 | //Because on wildcard and fuzzy searches, no text analysis is performed on the search word |
142 | 142 | //and no Analyseres get used |
143 | 143 | if ( strpos( $parts[1], '*' ) !== false ) { |
144 | 144 | $parts[1] = strtolower( $parts[1] ); |
145 | 145 | } |
146 | | - |
| 146 | + |
147 | 147 | //If we have a solrField Match add a ':' (its the Lucene equivalent of '=' ) |
148 | 148 | if ( $solrField ) { |
149 | 149 | $queryStr = $queryStr . ' ' . $solrField . ':' . $parts[1]; |
— | — | @@ -334,71 +334,71 @@ |
335 | 335 | } |
336 | 336 | switch ( $di->getDIType() ) { |
337 | 337 | 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; |
340 | 340 | break; |
341 | 341 | |
342 | 342 | case 1: |
343 | | - // /// Data item ID for SMWDINumber |
344 | | - // const TYPE_NUMBER = 1; |
| 343 | + // /// Data item ID for SMWDINumber |
| 344 | + // const TYPE_NUMBER = 1; |
345 | 345 | $solritem->addField( $propertyName . '_i', $di->getNumber() ); |
346 | 346 | $solritem->addSortField( $propertyName . '_i', $di->getNumber() ); |
347 | 347 | break; |
348 | 348 | |
349 | 349 | case 2: |
350 | | - // /// Data item ID for SMWDIString |
351 | | - // const TYPE_STRING = 2; |
| 350 | + // /// Data item ID for SMWDIString |
| 351 | + // const TYPE_STRING = 2; |
352 | 352 | $solritem->addField( $propertyName . '_t', $di->getString() ); |
353 | 353 | $solritem->addSortField( $propertyName . '_t', $di->getString() ); |
354 | 354 | break; |
355 | 355 | |
356 | 356 | case 3: |
357 | | - // /// Data item ID for SMWDIBlob |
358 | | - // const TYPE_BLOB = 3; |
| 357 | + // /// Data item ID for SMWDIBlob |
| 358 | + // const TYPE_BLOB = 3; |
359 | 359 | $solritem->addField( $propertyName . '_t', $di->getString() ); |
360 | 360 | $solritem->addSortField( $propertyName . '_t', $di->getString() ); |
361 | 361 | break; |
362 | 362 | |
363 | 363 | case 4: |
364 | | - // /// Data item ID for SMWDIBoolean |
365 | | - // const TYPE_BOOLEAN = 4; |
| 364 | + // /// Data item ID for SMWDIBoolean |
| 365 | + // const TYPE_BOOLEAN = 4; |
366 | 366 | $solritem->addField( $propertyName . '_b', $di->getBoolean() ); |
367 | 367 | $solritem->addSortField( $propertyName . '_b', $di->getBoolean() ); |
368 | 368 | break; |
369 | 369 | |
370 | 370 | case 5: |
371 | | - // /// Data item ID for SMWDIUri |
372 | | - // const TYPE_URI = 5; |
| 371 | + // /// Data item ID for SMWDIUri |
| 372 | + // const TYPE_URI = 5; |
373 | 373 | $solritem->addField( $propertyName . '_t', $di->getURI() ); |
374 | 374 | $solritem->addSortField( $propertyName . '_t', $di->getURI() ); |
375 | 375 | break; |
376 | 376 | |
377 | 377 | case 6: |
378 | | - // /// Data item ID for SMWDITimePoint |
379 | | - // const TYPE_TIME = 6; |
| 378 | + // /// Data item ID for SMWDITimePoint |
| 379 | + // const TYPE_TIME = 6; |
380 | 380 | $date = $di->getYear() . '-' . $di->getMonth() . '-' . $di->getDay() . 'T' . $di->getHour() . ':' . $di->getMinute() . ':' . $di->getSecond() . 'Z'; |
381 | 381 | $solritem->addField( $propertyName . '_dt', $date ); |
382 | 382 | $solritem->addSortField( $propertyName . '_dt', $date ); |
383 | 383 | break; |
384 | 384 | |
385 | 385 | case 7: |
386 | | - // /// Data item ID for SMWDIGeoCoord |
387 | | - // const TYPE_GEO = 7; |
| 386 | + // /// Data item ID for SMWDIGeoCoord |
| 387 | + // const TYPE_GEO = 7; |
388 | 388 | // TODO: Implement range Search in SOLR |
389 | 389 | $solritem->addField( $propertyName . '_lat', $di->getLatitude() ); |
390 | 390 | $solritem->addField( $propertyName . '_lng', $di->getLongitude() ); |
391 | 391 | break; |
392 | 392 | |
393 | 393 | case 8: |
394 | | - // /// Data item ID for SMWDIContainer |
395 | | - // const TYPE_CONTAINER = 8 |
| 394 | + // /// Data item ID for SMWDIContainer |
| 395 | + // const TYPE_CONTAINER = 8 |
396 | 396 | // TODO: What the hell is this used for? |
397 | 397 | $data->getSubject()->getTitle()->getText() . ' : '; |
398 | 398 | break; |
399 | 399 | |
400 | 400 | case 9: |
401 | | - // /// Data item ID for SMWDIWikiPage |
402 | | - // const TYPE_WIKIPAGE = 9; |
| 401 | + // /// Data item ID for SMWDIWikiPage |
| 402 | + // const TYPE_WIKIPAGE = 9; |
403 | 403 | $ns = $di->getNamespace(); |
404 | 404 | if ( $ns == 0 ) { |
405 | 405 | $solritem->addField( $propertyName . '_s', $di->getTitle() ); |
— | — | @@ -409,20 +409,20 @@ |
410 | 410 | break; |
411 | 411 | |
412 | 412 | case 10: |
413 | | - // /// Data item ID for SMWDIConcept |
414 | | - // const TYPE_CONCEPT = 10; |
| 413 | + // /// Data item ID for SMWDIConcept |
| 414 | + // const TYPE_CONCEPT = 10; |
415 | 415 | $data->getSubject()->getTitle()->getText() . ' : '; |
416 | 416 | break; |
417 | 417 | |
418 | 418 | case 11: |
419 | | - // /// Data item ID for SMWDIProperty |
420 | | - // const TYPE_PROPERTY = 11; |
| 419 | + // /// Data item ID for SMWDIProperty |
| 420 | + // const TYPE_PROPERTY = 11; |
421 | 421 | $data->getSubject()->getTitle()->getText() . ' : '; |
422 | 422 | break; |
423 | 423 | |
424 | 424 | case 12: |
425 | | - // /// Data item ID for SMWDIError |
426 | | - // const TYPE_ERROR = 12; |
| 425 | + // /// Data item ID for SMWDIError |
| 426 | + // const TYPE_ERROR = 12; |
427 | 427 | $data->getSubject()->getTitle()->getText() . ' : '; |
428 | 428 | break; |
429 | 429 | default: |