diff options
author | M Somerville <matthew-github@dracos.co.uk> | 2020-11-02 11:20:12 +0000 |
---|---|---|
committer | M Somerville <matthew-github@dracos.co.uk> | 2020-11-08 22:12:46 +0000 |
commit | 7359a017d4386c96cf681bb694f207138ebf0bc9 (patch) | |
tree | 54f48f0eedef6778ae8f065ab17bd03d08debdbd | |
parent | e08f14c4501f315b46c2a45b2f63b572ab650691 (diff) |
Ignore Low Bing geocoder results if any higher.
-rw-r--r-- | perllib/FixMyStreet/Geocode/Bing.pm | 14 | ||||
-rw-r--r-- | t/Mock/Bing.pm | 17 | ||||
-rw-r--r-- | t/geocode/bing.t | 6 |
3 files changed, 37 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/Geocode/Bing.pm b/perllib/FixMyStreet/Geocode/Bing.pm index 1b947abee..8c5366d3d 100644 --- a/perllib/FixMyStreet/Geocode/Bing.pm +++ b/perllib/FixMyStreet/Geocode/Bing.pm @@ -7,6 +7,7 @@ package FixMyStreet::Geocode::Bing; use strict; +use warnings; use FixMyStreet::Geocode; use Utils; @@ -52,6 +53,19 @@ sub string { my $results = $js->{resourceSets}->[0]->{resources}; my ( $error, @valid_locations, $latitude, $longitude ); + # If there are any High/Medium confidence results, don't include Low ones + my $exclude_low; + foreach (@$results) { + my $confidence = $_->{confidence}; + if ($confidence eq 'High' || $confidence eq 'Medium') { + $exclude_low = 1; + last; + } + } + if ($exclude_low) { + @$results = grep { $_->{confidence} ne 'Low' } @$results; + } + foreach (@$results) { my $address = $_->{name}; if ($params->{bing_country}) { diff --git a/t/Mock/Bing.pm b/t/Mock/Bing.pm index 77045950f..cc4dab845 100644 --- a/t/Mock/Bing.pm +++ b/t/Mock/Bing.pm @@ -19,6 +19,7 @@ sub dispatch_request { my $results = [ { point => { coordinates => [ 51, -1 ] }, name => 'Constitution Hill, London, SW1A', + confidence => 'High', address => { addressLine => 'Constitution Hill', locality => 'London', @@ -29,6 +30,7 @@ sub dispatch_request { push @$results, { point => { coordinates => [ 51, -1 ] }, name => 'Constitution Hill again, United Kingdom', + confidence => 'High', address => { addressLine => 'Constitution Hill again', locality => 'London', @@ -36,6 +38,21 @@ sub dispatch_request { } }; } + if ($query->{q} =~ /low/) { + push @$results, { + point => { coordinates => [ 52, -2 ] }, + name => 'Constitution Hill elsewhere, United Kingdom', + confidence => 'Low', + address => { + addressLine => 'Constitution Hill elsewhere', + locality => 'London', + countryRegion => 'United Kingdom', + } + }; + } + if ($query->{q} =~ /onlylow/) { + @$results = map { $_->{confidence} = 'Low'; $_ } @$results; + } my $data = { statusCode => 200, resourceSets => [ { resources => $results } ], diff --git a/t/geocode/bing.t b/t/geocode/bing.t index 32cffaa4e..156f983e1 100644 --- a/t/geocode/bing.t +++ b/t/geocode/bing.t @@ -21,4 +21,10 @@ FixMyStreet::override_config { is $r->{error}[1]{address}, 'Constitution Hill again, London'; }; +my $r = FixMyStreet::Geocode::Bing->string('two results andalow', $c); +is scalar @{$r->{error}}, 2; + +$r = FixMyStreet::Geocode::Bing->string('two results onlylow', $c); +is scalar @{$r->{error}}, 3; + done_testing; |