From 70a5f703818ec6429978a06b497d6276b0b93fce Mon Sep 17 00:00:00 2001 From: Peter Johnson <738069+missinglink@users.noreply.github.com> Date: Fri, 28 Nov 2025 12:50:41 +0100 Subject: [PATCH] feat(address_search_using_ids): add macrocounty as synonym for locality --- query/address_search_using_ids.js | 6 ++ test/unit/query/address_search_using_ids.js | 99 +++++++++++++++++++-- 2 files changed, 96 insertions(+), 9 deletions(-) diff --git a/query/address_search_using_ids.js b/query/address_search_using_ids.js index 720ee89d4..4273e336c 100644 --- a/query/address_search_using_ids.js +++ b/query/address_search_using_ids.js @@ -131,6 +131,12 @@ function generateQuery( clean, res ){ // find the first granularity band for which there are results const granularity_band = granularity_bands.find(band => anyResultsAtGranularityBand(results, band)); + // special case: if locality is present in the band, also include macrocounty + // this is used to cover the Greater Syndey Area + if (granularity_band && granularity_band.includes('locality')) { + granularity_band.push('macrocounty'); + } + // if there's a granularity band, accumulate the ids from each layer in the band // into an object mapping layer->ids of those layers if (granularity_band) { diff --git a/test/unit/query/address_search_using_ids.js b/test/unit/query/address_search_using_ids.js index 334b874fa..1c53d1228 100644 --- a/test/unit/query/address_search_using_ids.js +++ b/test/unit/query/address_search_using_ids.js @@ -287,14 +287,15 @@ module.exports.tests.granularity_bands = (test, common) => { const generatedQuery = generateQuery(clean, res); t.deepEquals(generatedQuery.body.vs.var('input:layers').$, { - neighbourhood: [1, 11], - borough: [2, 12], - locality: [3, 13], - localadmin: [4, 14], - region: [7, 17], - macroregion: [8, 18], - dependency: [9, 19], - country: [10, 20] + neighbourhood: [ 1, 11 ], + borough: [ 2, 12 ], + locality: [ 3, 13 ], + localadmin: [ 4, 14 ], + region: [ 7, 17 ], + macroregion: [ 8, 18 ], + dependency: [ 9, 19 ], + country: [ 10, 20 ], + macrocounty: [ 6, 16 ] }); t.end(); @@ -339,7 +340,8 @@ module.exports.tests.granularity_bands = (test, common) => { region: [], macroregion: [], dependency: [], - country: [] + country: [], + macrocounty: [] }); t.end(); @@ -609,6 +611,85 @@ module.exports.tests.boundary_filters = (test, common) => { }; +module.exports.tests.sydney_macrocounty = (test, common) => { + test('Refering to Greater Sydney area (macrocounty) rather than Sydney Metro Area (locality)', (t) => { + const logger = mock_logger(); + + const clean = { + text: '300 Burns Bay Road, Sydney, AU', + parsed_text: { + housenumber: '300', + street: 'burns bay road', + city: 'sydney', + country: 'AUS' + } + }; + const res = { + data: [ + { + layer: 'continent', + source_id: '102191583' + }, + { + layer: 'country', + source_id: '85632793' + }, + { + layer: 'county', + source_id: '102049151' + }, + { + layer: 'empire', + source_id: '136253039' + }, + { + layer: 'localadmin', + source_id: '404226357' + }, + { + layer: 'locality', + source_id: '101932003' + }, + { + layer: 'macrocounty', + source_id: '1376953385' + }, + { + layer: 'region', + source_id: '85681545' + } + ] + }; + + const generateQuery = proxyquire('../../../query/address_search_using_ids', { + 'pelias-logger': logger, + 'pelias-query': { + layout: { + AddressesUsingIdsQuery: MockQuery + }, + view: views, + Vars: require('pelias-query').Vars + } + }); + + const generatedQuery = generateQuery(clean, res); + + t.deepEquals(generatedQuery.body.vs.var('input:layers').$, { + neighbourhood: [], + borough: [], + locality: [ '101932003' ], + localadmin: [ '404226357' ], + region: [ '85681545' ], + macroregion: [], + dependency: [], + country: [ '85632793' ], + macrocounty: [ '1376953385' ] + }); + + t.end(); + }); +}; + module.exports.all = (tape, common) => { function test(name, testFunction) { return tape(`address_search_using_ids query ${name}`, testFunction);