Browse Source

Merge branch 'precision' of github.com:pelias/api into precision

pull/42/head
Peter Johnson 10 years ago
parent
commit
4c87a8bda0
  1. 19
      query/suggest.js
  2. 59
      test/unit/query/suggest.js

19
query/suggest.js

@ -4,6 +4,21 @@ var logger = require('../src/logger');
// Build pelias suggest query
function generate( params ){
var getPrecision = function(zoom) {
switch (true) {
case (zoom > 15):
return 5; // zoom: >= 16
case (zoom > 9):
return 4; // zoom: 10-15
case (zoom > 5):
return 3; // zoom: 6-9
case (zoom > 3):
return 2; // zoom: 4-5
default:
return 1; // zoom: 1-3 or when zoom: undefined
}
};
var cmd = {
'pelias' : {
'text' : params.input,
@ -14,9 +29,7 @@ function generate( params ){
'dataset': params.layers,
'location': {
'value': [ params.lon, params.lat ],
// // commented out until they fix the precision bug in ES 1.3.3
'precision': 2 // params.zoom > 9 ? 3 : (params.zoom > 7 ? 2 : 1)
'precision': getPrecision(params.zoom)
}
}
}

59
test/unit/query/suggest.js

@ -14,7 +14,7 @@ module.exports.tests.query = function(test, common) {
test('valid query', function(t) {
var query = generate({
input: 'test', size: 10,
lat: 0, lon: 0,
lat: 0, lon: 0, zoom:1,
layers: ['test']
});
var expected = {
@ -26,7 +26,7 @@ module.exports.tests.query = function(test, common) {
context: {
dataset: [ 'test' ],
location: {
precision: 2,
precision: 1,
value: [ 0, 0 ]
}
}
@ -38,6 +38,61 @@ module.exports.tests.query = function(test, common) {
});
};
module.exports.tests.precision = function(test, common) {
var test_cases = [
{zoom:1, precision:1},
{zoom:2, precision:1},
{zoom:3, precision:1},
{zoom:4, precision:2},
{zoom:5, precision:2},
{zoom:6, precision:3},
{zoom:7, precision:3},
{zoom:8, precision:3},
{zoom:9, precision:3},
{zoom:10, precision:4},
{zoom:11, precision:4},
{zoom:12, precision:4},
{zoom:13, precision:4},
{zoom:14, precision:4},
{zoom:15, precision:4},
{zoom:16, precision:5},
{zoom:17, precision:5},
{zoom:18, precision:5},
{zoom:19, precision:5},
{zoom:'', precision:1},
{zoom:null, precision:1},
{zoom:undefined, precision:1}
];
test_cases.forEach( function( test_case ){
test('valid precision where zoom = ' + test_case.zoom, function(t) {
var query = generate({
input: 'test', size: 10,
lat: 0, lon: 0, zoom:test_case.zoom,
layers: ['test']
});
var expected = {
pelias: {
text: 'test',
completion: {
field: 'suggest',
size: 10,
context: {
dataset: [ 'test' ],
location: {
precision: test_case.precision,
value: [ 0, 0 ]
}
}
}
}
};
t.deepEqual(query, expected, 'valid suggest query');
t.end();
});
});
};
module.exports.all = function (tape, common) {
function test(name, testFunction) {

Loading…
Cancel
Save