Browse Source

exclude venue, address, and street from layers filter

pull/912/head
Stephen Hess 8 years ago
parent
commit
98b6829e31
  1. 20
      controller/placeholder.js
  2. 136
      test/unit/controller/placeholder.js

20
controller/placeholder.js

@ -59,16 +59,16 @@ function hasName(result) {
}
// filter that passes only results that match on requested layers
// passes everything if req.clean.layers is not found
function getLayersFilter(clean) {
if (_.isEmpty(_.get(clean, 'layers', []))) {
return _.constant(true);
// passes everything if:
// - req.clean.layers is empty
// - req.clean.parsed_text.street is available
if (_.isEmpty(_.get(clean, 'layers', [])) || _.has(clean, ['parsed_text', 'street'])) {
return () => true;
}
// otherwise return a function that checks for set inclusion of a result placetype
return (result) => {
return _.includes(clean.layers, result.placetype);
};
return (result) => _.includes(clean.layers, result.placetype);
}
@ -222,12 +222,8 @@ function setup(placeholderService, should_execute) {
placeholderService(req, (err, results) => {
if (err) {
// bubble up an error if one occurred
if (_.isObject(err) && err.message) {
req.errors.push( err.message );
} else {
req.errors.push( err );
}
// push err.message or err onto req.errors
req.errors.push( _.get(err, 'message', err));
} else {
const boundaryCountry = _.get(req, ['clean', 'boundary.country']);

136
test/unit/controller/placeholder.js

@ -1143,6 +1143,142 @@ module.exports.tests.result_filtering = (test, common) => {
});
test('if req.clean.parsed_text contains street, don\'t filter on anything', (t) => {
const logger = mock_logger();
const placeholder_service = (req, callback) => {
t.deepEqual(req, {
param1: 'param1 value',
clean: {
layers: ['neighbourhood'],
parsed_text: {
street: 'street value'
}
}
});
const response = [
{
id: 1,
name: 'name 1',
placetype: 'neighbourhood',
lineage: [ {} ],
geom: {
area: 1,
lat: 14.141414,
lon: 41.414141
}
},
{
id: 2,
name: 'name 2',
placetype: 'borough',
lineage: [ {} ],
geom: {
area: 2,
lat: 15.151515,
lon: 51.515151
}
},
{
id: 3,
name: 'name 3',
placetype: 'locality',
lineage: [ {} ],
geom: {
area: 3,
lat: 16.161616,
lon: 61.616161
}
}
];
callback(null, response);
};
const controller = proxyquire('../../../controller/placeholder', {
'pelias-logger': logger
})(placeholder_service, _.constant(true));
const req = {
param1: 'param1 value',
clean: {
layers: ['neighbourhood'],
parsed_text: {
street: 'street value'
}
}
};
const res = { };
controller(req, res, () => {
const expected_res = {
meta: {},
data: [
{
_id: '1',
_type: 'neighbourhood',
layer: 'neighbourhood',
source: 'whosonfirst',
source_id: '1',
center_point: {
lat: 14.141414,
lon: 41.414141
},
name: {
'default': 'name 1'
},
phrase: {
'default': 'name 1'
},
parent: { }
},
{
_id: '2',
_type: 'borough',
layer: 'borough',
source: 'whosonfirst',
source_id: '2',
center_point: {
lat: 15.151515,
lon: 51.515151
},
name: {
'default': 'name 2'
},
phrase: {
'default': 'name 2'
},
parent: { }
},
{
_id: '3',
_type: 'locality',
layer: 'locality',
source: 'whosonfirst',
source_id: '3',
center_point: {
lat: 16.161616,
lon: 61.616161
},
name: {
'default': 'name 3'
},
phrase: {
'default': 'name 3'
},
parent: { }
}
]
};
t.deepEquals(res, expected_res);
t.ok(logger.isInfoMessage('[controller:placeholder] [result_count:3]'));
t.end();
});
});
test('only synthesized docs matching explicit boundary.country should be returned', (t) => {
const logger = require('pelias-mock-logger')();

Loading…
Cancel
Save