From 2f8169ac1095c9b942157f53255b4ac2e84bd260 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Wed, 9 Sep 2015 14:09:43 +0200 Subject: [PATCH] remove unused sort conditions --- helper/address_weights.js | 13 ---- helper/admin_weights.js | 13 ---- helper/category_weights.js | 17 ----- query/sort.js | 53 +------------- test/unit/fixture/search_full_address.js | 78 +-------------------- test/unit/fixture/search_regions_address.js | 78 +-------------------- test/unit/fixture/sort_default.js | 34 --------- test/unit/query/search.js | 11 +-- test/unit/query/sort.js | 43 +----------- test/unit/run.js | 1 - 10 files changed, 10 insertions(+), 331 deletions(-) delete mode 100644 helper/address_weights.js delete mode 100644 helper/admin_weights.js delete mode 100644 helper/category_weights.js diff --git a/helper/address_weights.js b/helper/address_weights.js deleted file mode 100644 index 6b15ab4c..00000000 --- a/helper/address_weights.js +++ /dev/null @@ -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 -}; diff --git a/helper/admin_weights.js b/helper/admin_weights.js deleted file mode 100644 index 3b53c423..00000000 --- a/helper/admin_weights.js +++ /dev/null @@ -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 -}; diff --git a/helper/category_weights.js b/helper/category_weights.js deleted file mode 100644 index 5176b70e..00000000 --- a/helper/category_weights.js +++ /dev/null @@ -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 -}; diff --git a/query/sort.js b/query/sort.js index 094e1462..8ffff81d 100644 --- a/query/sort.js +++ b/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; -} diff --git a/test/unit/fixture/search_full_address.js b/test/unit/fixture/search_full_address.js index 144dd0ca..7244f1ff 100644 --- a/test/unit/fixture/search_full_address.js +++ b/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 }; \ No newline at end of file diff --git a/test/unit/fixture/search_regions_address.js b/test/unit/fixture/search_regions_address.js index b0ec4208..d72c3aff 100644 --- a/test/unit/fixture/search_regions_address.js +++ b/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 }; \ No newline at end of file diff --git a/test/unit/fixture/sort_default.js b/test/unit/fixture/sort_default.js index 255e3b29..fa3edf36 100644 --- a/test/unit/fixture/sort_default.js +++ b/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' - } } ]; \ No newline at end of file diff --git a/test/unit/query/search.js b/test/unit/query/search.js index 667fdc26..e4f70b9a 100644 --- a/test/unit/query/search.js +++ b/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(); diff --git a/test/unit/query/sort.js b/test/unit/query/sort.js index f534d8ae..e170cdad 100644 --- a/test/unit/query/sort.js +++ b/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' } diff --git a/test/unit/run.js b/test/unit/run.js index d5d55676..bddc6072 100644 --- a/test/unit/run.js +++ b/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'), ];