Browse Source

remove unused sort conditions

pull/242/head
Peter Johnson 9 years ago
parent
commit
2f8169ac10
  1. 13
      helper/address_weights.js
  2. 13
      helper/admin_weights.js
  3. 17
      helper/category_weights.js
  4. 53
      query/sort.js
  5. 78
      test/unit/fixture/search_full_address.js
  6. 78
      test/unit/fixture/search_regions_address.js
  7. 34
      test/unit/fixture/sort_default.js
  8. 11
      test/unit/query/search.js
  9. 43
      test/unit/query/sort.js
  10. 1
      test/unit/run.js

13
helper/address_weights.js

@ -1,13 +0,0 @@
/**
* These values specify how much a document that matches certain parts of an address
* should be boosted in elasticsearch results.
*/
module.exports = {
number: 1,
street: 3,
zip: 3,
admin2: 2,
admin1_abbr: 3,
alpha3: 5
};

13
helper/admin_weights.js

@ -1,13 +0,0 @@
/**
* These values specify how much a document that matches a certain _type
* should be boosted in elasticsearch results.
*/
module.exports = {
'admin0': 4,
'admin1': 3,
'admin2': 2,
'local_admin': 1,
'locality':1,
'neighborhood':1
};

17
helper/category_weights.js

@ -1,17 +0,0 @@
/**
* These values specify how much a record that matches a certain category
* should be boosted in elasticsearch results.
*/
module.exports.default = {
'transport:air': 2,
'transport:air:aerodrome': 2,
'transport:air:airport': 2,
'admin': 2
};
module.exports.address = {
'transport:air': 2,
'transport:air:aerodrome': 2,
'transport:air:airport': 2
};

53
query/sort.js

@ -1,61 +1,23 @@
var admin_boost = 'admin_boost';
var population = 'population';
var popularity = 'popularity';
var category = 'category';
var category_weights = require('../helper/category_weights');
var admin_weights = require('../helper/admin_weights');
var weights = require('pelias-suggester-pipeline').weights;
var isObject = require( 'is-object' );
module.exports = function( params ){
var scriptsConfig = [
{
'_script': {
'file': admin_boost,
'file': 'admin_boost',
'type': 'number',
'order': 'desc'
}
},
{
'_script': {
'file': popularity,
'file': 'popularity',
'type': 'number',
'order': 'desc'
}
},
{
'_script': {
'file': population,
'type': 'number',
'order': 'desc'
}
},
{
'_script': {
'params': {
'weights': admin_weights
},
'file': 'weights',
'type': 'number',
'order': 'desc'
}
},
{
'_script': {
'params': {
'category_weights': getCategoryWeights(params)
},
'file': category,
'type': 'number',
'order': 'desc'
}
},
{
'_script': {
'params': {
'weights': weights
},
'file': 'weights',
'file': 'population',
'type': 'number',
'order': 'desc'
}
@ -64,12 +26,3 @@ module.exports = function( params ){
return scriptsConfig;
};
function getCategoryWeights(params) {
if (params && params.hasOwnProperty('parsed_text') &&
(params.parsed_text.hasOwnProperty('number') ||
params.parsed_text.hasOwnProperty('street'))) {
return category_weights.address;
}
return category_weights.default;
}

78
test/unit/fixture/search_full_address.js

@ -125,82 +125,6 @@ module.exports = {
}
},
'size': 10,
'sort': [
'_score',
{
'_script': {
'file': 'admin_boost',
'type': 'number',
'order': 'desc'
}
},
{
'_script': {
'file': 'popularity',
'type': 'number',
'order': 'desc'
}
},
{
'_script': {
'file': 'population',
'type': 'number',
'order': 'desc'
}
},
{
'_script': {
'params': {
'weights': {
'admin0': 4,
'admin1': 3,
'admin2': 2,
'local_admin': 1,
'locality': 1,
'neighborhood': 1
}
},
'file': 'weights',
'type': 'number',
'order': 'desc'
}
},
{
'_script': {
'params': {
'category_weights': {
'transport:air': 2,
'transport:air:aerodrome': 2,
'transport:air:airport': 2
}
},
'file': 'category',
'type': 'number',
'order': 'desc'
}
},
{
'_script': {
'params': {
'weights': {
'geoname': 0,
'address': 4,
'osmnode': 6,
'osmway': 6,
'poi-address': 8,
'neighborhood': 10,
'local_admin': 12,
'locality': 12,
'admin2': 12,
'admin1': 14,
'admin0': 2
}
},
'file': 'weights',
'type': 'number',
'order': 'desc'
}
}
],
'sort': [ '_score' ],
'track_scores': true
};

78
test/unit/fixture/search_regions_address.js

@ -109,82 +109,6 @@ module.exports = {
}
},
'size': 10,
'sort': [
'_score',
{
'_script': {
'file': 'admin_boost',
'type': 'number',
'order': 'desc'
}
},
{
'_script': {
'file': 'popularity',
'type': 'number',
'order': 'desc'
}
},
{
'_script': {
'file': 'population',
'type': 'number',
'order': 'desc'
}
},
{
'_script': {
'params': {
'weights': {
'admin0': 4,
'admin1': 3,
'admin2': 2,
'local_admin': 1,
'locality': 1,
'neighborhood': 1
}
},
'file': 'weights',
'type': 'number',
'order': 'desc'
}
},
{
'_script': {
'params': {
'category_weights': {
'transport:air': 2,
'transport:air:aerodrome': 2,
'transport:air:airport': 2
}
},
'file': 'category',
'type': 'number',
'order': 'desc'
}
},
{
'_script': {
'params': {
'weights': {
'geoname': 0,
'address': 4,
'osmnode': 6,
'osmway': 6,
'poi-address': 8,
'neighborhood': 10,
'local_admin': 12,
'locality': 12,
'admin2': 12,
'admin1': 14,
'admin0': 2
}
},
'file': 'weights',
'type': 'number',
'order': 'desc'
}
}
],
'sort': [ '_score' ],
'track_scores': true
};

34
test/unit/fixture/sort_default.js

@ -1,8 +1,4 @@
var category_weights = require('../../../helper/category_weights');
var admin_weights = require('../../../helper/admin_weights');
var weights = require('pelias-suggester-pipeline').weights;
module.exports = [
'_score',
{
@ -25,35 +21,5 @@ module.exports = [
'type': 'number',
'order': 'desc'
}
},
{
'_script': {
'params': {
'weights': admin_weights
},
'file': 'weights',
'type': 'number',
'order': 'desc'
}
},
{
'_script': {
'params': {
'category_weights': category_weights.default
},
'file': 'category',
'type': 'number',
'order': 'desc'
}
},
{
'_script': {
'params': {
'weights': weights
},
'file': 'weights',
'type': 'number',
'order': 'desc'
}
}
];

11
test/unit/query/search.js

@ -1,15 +1,6 @@
var generate = require('../../../query/search');
var admin_boost = 'admin_boost';
var population = 'population';
var popularity = 'popularity';
var category = 'category';
var parser = require('../../../helper/query_parser');
var category_weights = require('../../../helper/category_weights');
var admin_weights = require('../../../helper/admin_weights');
var address_weights = require('../../../helper/address_weights');
var weights = require('pelias-suggester-pipeline').weights;
module.exports.tests = {};
@ -100,6 +91,7 @@ module.exports.tests.query = function(test, common) {
});
var expected = require('../fixture/search_full_address');
expected.sort = sort;
t.deepEqual(query, expected, 'valid search query');
t.end();
@ -133,6 +125,7 @@ module.exports.tests.query = function(test, common) {
});
var expected = require('../fixture/search_regions_address');
expected.sort = sort;
t.deepEqual(query, expected, 'valid search query');
t.end();

43
test/unit/query/sort.js

@ -1,12 +1,5 @@
var generate = require('../../../query/sort');
var admin_boost = 'admin_boost';
var population = 'population';
var popularity = 'popularity';
var category = 'category';
var category_weights = require('../../../helper/category_weights');
var admin_weights = require('../../../helper/admin_weights');
var weights = require('pelias-suggester-pipeline').weights;
module.exports.tests = {};
@ -21,51 +14,21 @@ module.exports.tests.interface = function(test, common) {
var expected = [
{
'_script': {
'file': admin_boost,
'file': 'admin_boost',
'type': 'number',
'order': 'desc'
}
},
{
'_script': {
'file': popularity,
'file': 'popularity',
'type': 'number',
'order': 'desc'
}
},
{
'_script': {
'file': population,
'type': 'number',
'order': 'desc'
}
},
{
'_script': {
'params': {
'weights': admin_weights
},
'file': 'weights',
'type': 'number',
'order': 'desc'
}
},
{
'_script': {
'params': {
'category_weights': category_weights.default
},
'file': category,
'type': 'number',
'order': 'desc'
}
},
{
'_script': {
'params': {
'weights': weights
},
'file': 'weights',
'file': 'population',
'type': 'number',
'order': 'desc'
}

1
test/unit/run.js

@ -19,7 +19,6 @@ var tests = [
require('./helper/query_parser'),
require('./helper/geojsonify'),
require('./helper/outputSchema'),
require('./helper/adminFields'),
require('./helper/types'),
];

Loading…
Cancel
Save