Browse Source

moving the query in one place. adding tests

fuzzy
Harish Krishna 10 years ago
parent
commit
289cd745b2
  1. 5
      controller/suggest.js
  2. 5
      query/suggest.js
  3. 1
      test/unit/controller/suggest.js
  4. 38
      test/unit/query/suggest.js

5
controller/suggest.js

@ -104,10 +104,7 @@ function setup( backend, query ){
// fuzzy
async_query.fuzzy = function(callback){
cmd.body = query( req.clean, 3 );
cmd.body.pelias.completion.fuzzy = {
'fuzziness': 'AUTO'
};
cmd.body = query( req.clean, 3, 'AUTO' );
query_backend(cmd, callback);
};

5
query/suggest.js

@ -2,7 +2,7 @@
var logger = require('../src/logger');
// Build pelias suggest query
function generate( params, precision ){
function generate( params, precision, fuzziness ){
var getPrecision = function(zoom) {
switch (true) {
@ -31,6 +31,9 @@ function generate( params, precision ){
'value': [ params.lon, params.lat ],
'precision': precision || getPrecision(params.zoom)
}
},
'fuzzy' : {
'fuzziness': fuzziness || 0
}
}
}

1
test/unit/controller/suggest.js

@ -43,6 +43,7 @@ module.exports.tests.functional_success = function(test, common) {
test('functional success', function(t) {
var backend = mockBackend( 'client/suggest/ok/1', function( cmd ){
console.log(cmd)
if (cmd.body.layers) {
// layers are set exclusively for admin: test for admin-only layers
t.deepEqual(cmd, { body: { input: 'b', layers: [ 'admin0', 'admin1', 'admin2' ] }, index: 'pelias' }, 'correct backend command');

38
test/unit/query/suggest.js

@ -29,7 +29,8 @@ module.exports.tests.query = function(test, common) {
precision: 1,
value: [ 0, 0 ]
}
}
},
fuzzy: { fuzziness: 0 },
}
}
};
@ -82,7 +83,8 @@ module.exports.tests.precision = function(test, common) {
precision: test_case.precision,
value: [ 0, 0 ]
}
}
},
fuzzy: { fuzziness: 0 },
}
}
};
@ -92,6 +94,38 @@ module.exports.tests.precision = function(test, common) {
});
};
module.exports.tests.fuzziness = function(test, common) {
var test_cases = [0,1,2,'AUTO', undefined, null, ''];
test('valid fuzziness', function(t) {
test_cases.forEach( function( test_case ){
var query = generate({
input: 'test', size: 10,
lat: 0, lon: 0, zoom:0,
layers: ['test']
}, undefined, test_case);
var expected = {
pelias: {
text: 'test',
completion: {
field: 'suggest',
size: 10,
context: {
dataset: [ 'test' ],
location: {
precision: 1,
value: [ 0, 0 ]
}
},
fuzzy: { fuzziness: test_case || 0 },
}
}
};
t.deepEqual(query, expected, 'valid suggest query for fuziness = ' + test_case);
});
t.end();
});
};
module.exports.all = function (tape, common) {
function test(name, testFunction) {

Loading…
Cancel
Save