Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom layers by removing the restriction for non-coarse layers #1631

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions query/reverse.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const _ = require('lodash');
const peliasQuery = require('pelias-query');
const peliasConfig = require('pelias-config').generate();
const defaults = require('./reverse_defaults');

//------------------------------
Expand Down Expand Up @@ -39,8 +40,7 @@ function generateQuery( clean ){

// layers
if( _.isArray(clean.layers) && !_.isEmpty(clean.layers) ) {
// only include non-coarse layers
vs.var( 'layers', _.intersection(clean.layers, ['address', 'street', 'venue']));
vs.var( 'layers', _.difference(clean.layers, peliasConfig.api.targets.layer_aliases.coarse));
mansoor-sajjad marked this conversation as resolved.
Show resolved Hide resolved
}

// focus point to score by distance
Expand Down
1 change: 0 additions & 1 deletion query/reverse_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module.exports = _.merge({}, peliasQuery.defaults, {

'size': 1,
'track_scores': true,
'layers': ['venue', 'address', 'street'],

'centroid:field': 'center_point',

Expand Down
46 changes: 42 additions & 4 deletions test/unit/query/reverse.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ module.exports.tests.query = (test, common) => {
t.notOk(query.body.vs.isset('input:categories'));
t.notOk(query.body.vs.isset('boundary:gid'));

t.deepEquals(query.body.score_functions, [
]);
t.deepEquals(query.body.score_functions, []);

t.deepEquals(query.body.filter_functions, [
'boundary_circle view',
Expand Down Expand Up @@ -209,12 +208,31 @@ module.exports.tests.layers = (test, common) => {

});

test('non-empty array clean.layers should only set non-coarse layers in vs', t => {
test('non-empty array clean.layers should only set non-coarse layers in vs, using user-defined configuration for coarse layers', t => {
const clean = {
layers: all_layers
};

const config_with_coarse_layers = {
generate: function () {
return {
api: {
targets: {
layer_aliases: {
coarse: [
'country',
'county',
'locality'
]
}
}
}
};
}
};

const query = proxyquire('../../../query/reverse', {
'pelias-config': config_with_coarse_layers,
'pelias-query': {
layout: {
FilteredBooleanQuery: MockQuery
Expand All @@ -225,11 +243,31 @@ module.exports.tests.layers = (test, common) => {
'./reverse_defaults': {}
})(clean);

t.deepEquals(query.body.vs.var('layers').toString(), ['address', 'venue', 'street']);
t.deepEquals(query.body.vs.var('layers').toString(), _.difference(clean.layers, ['country', 'county', 'locality']));
t.end();

});

test('non-empty array clean.layers should only set non-coarse layers in vs, using default configuration for coarse layers', t => {
const clean = {
layers: all_layers
};

const query = proxyquire('../../../query/reverse', {
'pelias-query': {
layout: {
FilteredBooleanQuery: MockQuery
},
view: views,
Vars: require('pelias-query').Vars
},
'./reverse_defaults': {}
})(clean);

t.deepEquals(query.body.vs.var('layers').toString(), [ 'address', 'venue', 'street' ]);
t.end();

});
};

module.exports.tests.focus_point = (test, common) => {
Expand Down