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 1 commit
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
3 changes: 2 additions & 1 deletion 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,7 +40,7 @@ function generateQuery( clean ){

// layers
if( _.isArray(clean.layers) && !_.isEmpty(clean.layers) ) {
vs.var( 'layers', clean.layers);
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
63 changes: 61 additions & 2 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,6 +208,66 @@ module.exports.tests.layers = (test, common) => {

});

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
},
view: views,
Vars: require('pelias-query').Vars
},
'./reverse_defaults': {}
})(clean);

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