Making WordPress.org


Ignore:
Timestamp:
11/26/2020 08:44:56 AM (4 years ago)
Author:
dd32
Message:

Events API: Handle queries with more than 3 "words" in the search by searching backwards until one matches. Improves matches for multi-word cities/countries.

Searches A B C D E, A B C D, A B C, A B, A for when no exact match is found.

See #3728.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/api.wordpress.org/public_html/events/1.0/index.php

    r10469 r10470  
    312312     */
    313313    $location_name_parts = preg_split( '/\s+/u', $location_name );
    314     $location_word_count = is_array( $location_name_parts ) ? count( $location_name_parts ) : 1;
    315 
    316     if ( ! $guess && $location_word_count >= 2 ) {
    317         // Catch input like "Portland Maine"
    318         $guess = guess_location_from_geonames( $location_name_parts[0], $timezone, $country_code, $wildcard = false );
    319     }
    320 
    321     if ( ! $guess && $location_word_count >= 3 ) {
    322         // Catch input like "Sao Paulo Brazil"
    323         $city_name = sprintf( '%s %s', $location_name_parts[0], $location_name_parts[1] );
    324         $guess     = guess_location_from_geonames( $city_name, $timezone, $country_code, $wildcard = false );
     314    $location_word_count = count( $location_name_parts );
     315
     316    // Catch input like "Portland Maine" and "Sao Paulo Brazil"
     317    if ( ! $guess && $location_word_count > 1 ) {
     318        foreach ( range( $location_word_count - 1, 1 ) as $i ) {
     319            $city_name = implode( ' ', array_slice( $location_name_parts, 0, $i ) );
     320            $guess     = guess_location_from_geonames( $city_name, $timezone, $country_code, $wildcard = false );
     321
     322            if ( $guess ) {
     323                break; // end foreach
     324            }
     325        }
    325326    }
    326327
     
    386387            mb_strlen( $location_name )
    387388        ) );
    388     }
    389 
    390     // Strip off null bytes
    391     // @todo Modify geoname script to to this instead?
    392     if ( ! empty( $row->name ) ) {
    393         $row->name = trim( $row->name );
    394389    }
    395390
Note: See TracChangeset for help on using the changeset viewer.