Browse Source

refactor: clean up sorting conditions

pull/242/head
Peter Johnson 9 years ago
parent
commit
c0f20aabd3
  1. 2
      package.json
  2. 3
      query/reverse.js
  3. 13
      query/search.js
  4. 28
      query/sort.js
  5. 55
      test/unit/query/sort.js
  6. 1
      test/unit/run.js

2
package.json

@ -49,7 +49,7 @@
"pelias-config": "^1.0.1",
"pelias-esclient": "0.0.25",
"pelias-logger": "^0.0.8",
"pelias-query": "^1.4.0",
"pelias-query": "^1.5.0",
"pelias-schema": "1.0.0",
"pelias-suggester-pipeline": "2.0.2",
"stats-lite": "^1.0.3",

3
query/reverse.js

@ -1,7 +1,6 @@
var peliasQuery = require('pelias-query'),
defaults = require('./defaults'),
sort = require('./sort');
defaults = require('./defaults');
//------------------------------
// reverse geocode query

13
query/search.js

@ -1,7 +1,6 @@
var peliasQuery = require('pelias-query'),
defaults = require('./defaults'),
sort = require('../query/sort'),
adminFields = require('../helper/adminFields')();
//------------------------------
@ -36,6 +35,11 @@ query.score( peliasQuery.view.admin('neighborhood') );
query.filter( peliasQuery.view.boundary_circle );
query.filter( peliasQuery.view.boundary_rect );
// groovy scripts used to handle tie-breaking
query.sort( peliasQuery.view.sort_numeric_script('admin_boost') );
query.sort( peliasQuery.view.sort_numeric_script('popularity') );
query.sort( peliasQuery.view.sort_numeric_script('population') );
// --------------------------------
/**
@ -183,12 +187,7 @@ function generateQuery( clean ){
}
}
var result = query.render( vs );
// @todo: remove unnessesary sort conditions
result.sort = result.sort.concat( sort( clean ) );
return result;
return query.render( vs );
}
module.exports = generateQuery;

28
query/sort.js

@ -1,28 +0,0 @@
module.exports = function( params ){
var scriptsConfig = [
{
'_script': {
'file': 'admin_boost',
'type': 'number',
'order': 'desc'
}
},
{
'_script': {
'file': 'popularity',
'type': 'number',
'order': 'desc'
}
},
{
'_script': {
'file': 'population',
'type': 'number',
'order': 'desc'
}
}
];
return scriptsConfig;
};

55
test/unit/query/sort.js

@ -1,55 +0,0 @@
var generate = require('../../../query/sort');
module.exports.tests = {};
module.exports.tests.interface = function(test, common) {
test('valid interface', function(t) {
t.equal(typeof generate(), 'object', 'valid object');
t.equal(typeof generate({input: 'foobar'}), 'object', 'valid object');
t.end();
});
};
var expected = [
{
'_script': {
'file': 'admin_boost',
'type': 'number',
'order': 'desc'
}
},
{
'_script': {
'file': 'popularity',
'type': 'number',
'order': 'desc'
}
},
{
'_script': {
'file': 'population',
'type': 'number',
'order': 'desc'
}
}
];
module.exports.tests.query = function(test, common) {
test('valid part of query', function(t) {
t.deepEqual(generate(), expected, 'valid sort part of the query');
t.deepEqual(generate( {} ), expected, 'valid sort part of the query');
t.end();
});
};
module.exports.all = function (tape, common) {
function test(name, testFunction) {
return tape('sort query ' + name, testFunction);
}
for( var testCase in module.exports.tests ){
module.exports.tests[testCase](test, common);
}
};

1
test/unit/run.js

@ -13,7 +13,6 @@ var tests = [
require('./sanitiser/reverse'),
require('./sanitiser/place'),
require('./query/types'),
require('./query/sort'),
require('./query/search'),
require('./query/autocomplete'),
require('./query/reverse'),

Loading…
Cancel
Save