From 898896bc24020f9bc7bfb3e287fb1f7f1e1ff585 Mon Sep 17 00:00:00 2001 From: Harish Krishna Date: Thu, 2 Apr 2015 14:22:48 -0400 Subject: [PATCH 1/2] giving request layers higher precedence (compared to the layers specified in queryMixer) --- query/suggest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/query/suggest.js b/query/suggest.js index 571b135e..249f7c38 100644 --- a/query/suggest.js +++ b/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() From e586b49d1d3e868344749f712cbe83ad7b5e5f31 Mon Sep 17 00:00:00 2001 From: Harish Krishna Date: Thu, 2 Apr 2015 15:38:47 -0400 Subject: [PATCH 2/2] tests - that check if the layers are being set correctly for suggesters and using query mixers right --- test/unit/query/suggest.js | 53 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/test/unit/query/suggest.js b/test/unit/query/suggest.js index de442ffb..d1067af0 100644 --- a/test/unit/query/suggest.js +++ b/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) {