Browse Source

Merge pull request #90 from pelias/suggester-fix

Allow consumers to filter suggestions by layer on '/suggest'
pull/107/head
Harish Krishna 10 years ago
parent
commit
3968034f80
  1. 2
      query/suggest.js
  2. 53
      test/unit/query/suggest.js

2
query/suggest.js

@ -34,7 +34,7 @@ function generate( params, query_mixer, fuzziness ){
'size' : this.params.size,
'field' : 'suggest',
'context': {
'dataset': layers || this.params.layers,
'dataset': this.params.layers || layers,
'location': {
'value': null,
'precision': precision || this.get_precision()

53
test/unit/query/suggest.js

@ -1,5 +1,6 @@
var generate = require('../../../query/suggest');
var queryMixer = require('../../../helper/queryMixer');
module.exports.tests = {};
@ -152,6 +153,58 @@ module.exports.tests.fuzziness = function(test, common) {
});
};
module.exports.tests.queryMixer = function(test, common) {
test('valid query mixer', function(t) {
for (var suggester in queryMixer) {
var queryMix = queryMixer[suggester];
var number_of_suggesters = queryMix.reduce(function(sum, query) {
return sum + (query.precision.length || 1);
}, 0);
var query = generate({
input: 'test', size: 10,
lat: 0, lon: 0, zoom:0
}, queryMix);
// adding one to number_of_suggesters to account for the key "text" in query.
t.deepEqual(Object.keys(query).length, number_of_suggesters + 1,
suggester + ' has correct number of suggesters'
);
}
t.end();
});
};
var isValidLayer = function(t, query, layers) {
for(var qKey in query) {
var q = query[qKey];
if (q.completion) {
var query_layers = q.completion.context.dataset;
t.deepEqual(query_layers, layers, layers + ' layers set correctly');
}
}
};
module.exports.tests.layers = function(test, common) {
test('valid layers with query-mixers', function(t) {
for (var suggester in queryMixer) {
var queryMix = queryMixer[suggester];
var layers= ['geoname', 'osm'];
var query = generate({
input: 'test', size: 10,
lat: 0, lon: 0, zoom:0,
layers: layers
}, queryMix);
isValidLayer(t, query, layers);
}
t.end();
});
};
module.exports.all = function (tape, common) {
function test(name, testFunction) {

Loading…
Cancel
Save