Making WordPress.org

Changeset 9640


Ignore:
Timestamp:
03/29/2020 01:47:54 AM (5 years ago)
Author:
dd32
Message:

Events API: Add an exact-match clause to the SQL ordering to ensure that the closest match for the provided location name is returned when there exist multiple variants of the same city with different accents.

See #5117.

File:
1 edited

Legend:

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

    r9349 r9640  
    301301            FIELD( %s, country  ) DESC,
    302302            FIELD( %s, timezone ) DESC,
    303             population DESC
     303            population DESC,
     304            BINARY LOWER( %s ) = BINARY LOWER( name ) DESC
    304305        LIMIT 1";
    305306
    306     $prepared_query = $wpdb->prepare( $query, $location_name, $country, $timezone );
     307    $prepared_query = $wpdb->prepare( $query, $location_name, $country, $timezone, $location_name );
    307308    $db_handle      = $wpdb->db_connect( $prepared_query );
    308309
     
    320321                FIELD( %s, country  ) DESC,
    321322                FIELD( %s, timezone ) DESC,
    322                 population DESC
     323                population DESC,
     324                BINARY LOWER( %s ) = BINARY LOWER( LEFT( name, %d ) ) DESC
    323325            LIMIT 1";
    324326
    325         $prepared_query = $wpdb->prepare( $query, $wpdb->esc_like( $location_name ) . '%', $country, $timezone );
     327        $prepared_query = $wpdb->prepare( $query, $wpdb->esc_like( $location_name ) . '%', $country, $timezone, $location_name, mb_strlen( $location_name ) );
    326328        $db_handle      = $wpdb->db_connect( $prepared_query );
    327329
Note: See TracChangeset for help on using the changeset viewer.