Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions query/address_search_using_ids.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
99 changes: 90 additions & 9 deletions test/unit/query/address_search_using_ids.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -339,7 +340,8 @@ module.exports.tests.granularity_bands = (test, common) => {
region: [],
macroregion: [],
dependency: [],
country: []
country: [],
macrocounty: []
});

t.end();
Expand Down Expand Up @@ -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);
Expand Down