Making WordPress.org

Changeset 4883


Ignore:
Timestamp:
02/04/2017 03:25:33 PM (8 years ago)
Author:
tellyworth
Message:

Events: search location as an exact literal string.

File:
1 edited

Legend:

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

    r4882 r4883  
    6767    // The FIELD() orderings give preference to rows that match the country and/or timezone, without excluding rows that don't match.
    6868    // And we sort by population desc, assuming that the biggest matching location is the most likely one.
    69     $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM geoname WHERE MATCH(name,asciiname,alternatenames) AGAINST(%s) ORDER BY FIELD(%s, country) DESC, FIELD(%s, timezone) DESC, population DESC LIMIT 1", $location_name, $country, $timezone ) );
     69
     70    // Strip quotes from the search query and enclose it in double quotes, to force an exact literal search
     71    $location_name = '"' . strtr( $location_name, [ '"' => '', "'" => '' ] ) . '"';
     72    $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM geoname WHERE MATCH(name,asciiname,alternatenames) AGAINST(%s IN BOOLEAN MODE) ORDER BY FIELD(%s, country) DESC, FIELD(%s, timezone) DESC, population DESC LIMIT 1", $location_name, $country, $timezone ) );
    7073    return $row;
    7174}
Note: See TracChangeset for help on using the changeset viewer.