Browse Source

fix: Merge pull request #874 from pelias/size-param-improvements

Always query for a minimum of 20 results from Elasticsearch
pull/876/head v3.26.1
Julian Simioni 8 years ago committed by GitHub
parent
commit
3427058cbb
  1. 11
      middleware/sizeCalculator.js
  2. 12
      test/unit/helper/sizeCalculator.js

11
middleware/sizeCalculator.js

@ -2,6 +2,8 @@ var _ = require('lodash');
var SIZE_PADDING = 2;
var MIN_QUERY_SIZE = 20;
/**
* Utility for calculating query result size
* incorporating padding for dedupe process
@ -24,12 +26,7 @@ function setup() {
* @returns {number}
*/
function calculateSize(cleanSize) {
switch (cleanSize || 1) {
case 1:
return 1;
default:
return cleanSize * SIZE_PADDING;
}
return Math.max(MIN_QUERY_SIZE, cleanSize * SIZE_PADDING);
}
module.exports = setup;
module.exports = setup;

12
test/unit/helper/sizeCalculator.js

@ -25,7 +25,7 @@ module.exports.tests.valid = function(test, common) {
test('size=0', function (t) {
setup(0);
calcSize(req, {}, function () {
t.equal(req.clean.querySize, 1);
t.equal(req.clean.querySize, 20);
t.end();
});
});
@ -33,7 +33,7 @@ module.exports.tests.valid = function(test, common) {
test('size=1', function (t) {
setup(1);
calcSize(req, {}, function () {
t.equal(req.clean.querySize, 1);
t.equal(req.clean.querySize, 20);
t.end();
});
});
@ -46,6 +46,14 @@ module.exports.tests.valid = function(test, common) {
});
});
test('size=20', function (t) {
setup(20);
calcSize(req, {}, function () {
t.equal(req.clean.querySize, 40);
t.end();
});
});
test('no size', function (t) {
setup();
calcSize(req, {}, function () {

Loading…
Cancel
Save