From 49d37eafed15072d6e35e5ce42bcc4e79e3ba4a4 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Tue, 20 Oct 2015 17:10:01 +0200 Subject: [PATCH] one config per query --- query/autocomplete.js | 2 +- .../{defaults.js => autocomplete_defaults.js} | 0 query/reverse.js | 2 +- query/reverse_defaults.js | 95 +++++++++++++++++++ query/search.js | 2 +- query/search_defaults.js | 95 +++++++++++++++++++ sanitiser/_geo_reverse.js | 2 +- test/unit/query/autocomplete_defaults.js | 22 +++++ test/unit/query/reverse_defaults.js | 22 +++++ .../query/{defaults.js => search_defaults.js} | 4 +- test/unit/run.js | 4 +- test/unit/sanitiser/_geo_reverse.js | 2 +- test/unit/sanitiser/reverse.js | 2 +- 13 files changed, 245 insertions(+), 9 deletions(-) rename query/{defaults.js => autocomplete_defaults.js} (100%) create mode 100644 query/reverse_defaults.js create mode 100644 query/search_defaults.js create mode 100644 test/unit/query/autocomplete_defaults.js create mode 100644 test/unit/query/reverse_defaults.js rename test/unit/query/{defaults.js => search_defaults.js} (77%) diff --git a/query/autocomplete.js b/query/autocomplete.js index ad64413a..0e9b9d68 100644 --- a/query/autocomplete.js +++ b/query/autocomplete.js @@ -1,6 +1,6 @@ var peliasQuery = require('pelias-query'), - defaults = require('./defaults'), + defaults = require('./autocomplete_defaults'), check = require('check-types'); //------------------------------ diff --git a/query/defaults.js b/query/autocomplete_defaults.js similarity index 100% rename from query/defaults.js rename to query/autocomplete_defaults.js diff --git a/query/reverse.js b/query/reverse.js index fd84b427..b48597c1 100644 --- a/query/reverse.js +++ b/query/reverse.js @@ -1,5 +1,5 @@ var peliasQuery = require('pelias-query'), - defaults = require('./defaults'), + defaults = require('./reverse_defaults'), check = require('check-types'); //------------------------------ diff --git a/query/reverse_defaults.js b/query/reverse_defaults.js new file mode 100644 index 00000000..b61e84ac --- /dev/null +++ b/query/reverse_defaults.js @@ -0,0 +1,95 @@ + +var peliasQuery = require('pelias-query'), + extend = require('extend'); + +module.exports = extend( false, peliasQuery.defaults, { + + 'size': 10, + 'track_scores': true, + + 'centroid:field': 'center_point', + + 'sort:distance:order': 'asc', + 'sort:distance:distance_type': 'plane', + + 'boundary:circle:radius': '50km', + 'boundary:circle:distance_type': 'plane', + 'boundary:circle:optimize_bbox': 'indexed', + 'boundary:circle:_cache': true, + + 'boundary:rect:type': 'indexed', + 'boundary:rect:_cache': true, + + 'ngram:analyzer': 'peliasOneEdgeGram', + 'ngram:field': 'name.default', + 'ngram:boost': 1, + + 'phrase:analyzer': 'peliasPhrase', + 'phrase:field': 'phrase.default', + 'phrase:boost': 1, + 'phrase:slop': 2, + + 'focus:function': 'linear', + 'focus:offset': '1km', + 'focus:scale': '50km', + 'focus:decay': 0.5, + 'focus:weight': 2, + + 'function_score:score_mode': 'avg', + 'function_score:boost_mode': 'replace', + + 'address:housenumber:analyzer': 'standard', + 'address:housenumber:field': 'address.number', + 'address:housenumber:boost': 2, + + 'address:street:analyzer': 'standard', + 'address:street:field': 'address.street', + 'address:street:boost': 5, + + 'address:postcode:analyzer': 'standard', + 'address:postcode:field': 'address.zip', + 'address:postcode:boost': 3, + + 'admin:alpha3:analyzer': 'standard', + 'admin:alpha3:field': 'alpha3', + 'admin:alpha3:boost': 5, + + 'admin:admin0:analyzer': 'peliasAdmin', + 'admin:admin0:field': 'admin0', + 'admin:admin0:boost': 4, + + 'admin:admin1:analyzer': 'peliasAdmin', + 'admin:admin1:field': 'admin1', + 'admin:admin1:boost': 3, + + 'admin:admin1_abbr:analyzer': 'peliasAdmin', + 'admin:admin1_abbr:field': 'admin1_abbr', + 'admin:admin1_abbr:boost': 3, + + 'admin:admin2:analyzer': 'peliasAdmin', + 'admin:admin2:field': 'admin2', + 'admin:admin2:boost': 2, + + 'admin:local_admin:analyzer': 'peliasAdmin', + 'admin:local_admin:field': 'local_admin', + 'admin:local_admin:boost': 1, + + 'admin:locality:analyzer': 'peliasAdmin', + 'admin:locality:field': 'locality', + 'admin:locality:boost': 1, + + 'admin:neighborhood:analyzer': 'peliasAdmin', + 'admin:neighborhood:field': 'neighborhood', + 'admin:neighborhood:boost': 1, + + 'popularity:field': 'popularity', + 'popularity:modifier': 'log1p', + 'popularity:max_boost': 20, + 'popularity:weight': 1, + + 'population:field': 'population', + 'population:modifier': 'log1p', + 'population:max_boost': 20, + 'population:weight': 2 + +}); diff --git a/query/search.js b/query/search.js index a30aa2fe..da7773a9 100644 --- a/query/search.js +++ b/query/search.js @@ -1,5 +1,5 @@ var peliasQuery = require('pelias-query'), - defaults = require('./defaults'), + defaults = require('./search_defaults'), textParser = require('./text_parser'), check = require('check-types'), geolib = require('geolib'); diff --git a/query/search_defaults.js b/query/search_defaults.js new file mode 100644 index 00000000..b61e84ac --- /dev/null +++ b/query/search_defaults.js @@ -0,0 +1,95 @@ + +var peliasQuery = require('pelias-query'), + extend = require('extend'); + +module.exports = extend( false, peliasQuery.defaults, { + + 'size': 10, + 'track_scores': true, + + 'centroid:field': 'center_point', + + 'sort:distance:order': 'asc', + 'sort:distance:distance_type': 'plane', + + 'boundary:circle:radius': '50km', + 'boundary:circle:distance_type': 'plane', + 'boundary:circle:optimize_bbox': 'indexed', + 'boundary:circle:_cache': true, + + 'boundary:rect:type': 'indexed', + 'boundary:rect:_cache': true, + + 'ngram:analyzer': 'peliasOneEdgeGram', + 'ngram:field': 'name.default', + 'ngram:boost': 1, + + 'phrase:analyzer': 'peliasPhrase', + 'phrase:field': 'phrase.default', + 'phrase:boost': 1, + 'phrase:slop': 2, + + 'focus:function': 'linear', + 'focus:offset': '1km', + 'focus:scale': '50km', + 'focus:decay': 0.5, + 'focus:weight': 2, + + 'function_score:score_mode': 'avg', + 'function_score:boost_mode': 'replace', + + 'address:housenumber:analyzer': 'standard', + 'address:housenumber:field': 'address.number', + 'address:housenumber:boost': 2, + + 'address:street:analyzer': 'standard', + 'address:street:field': 'address.street', + 'address:street:boost': 5, + + 'address:postcode:analyzer': 'standard', + 'address:postcode:field': 'address.zip', + 'address:postcode:boost': 3, + + 'admin:alpha3:analyzer': 'standard', + 'admin:alpha3:field': 'alpha3', + 'admin:alpha3:boost': 5, + + 'admin:admin0:analyzer': 'peliasAdmin', + 'admin:admin0:field': 'admin0', + 'admin:admin0:boost': 4, + + 'admin:admin1:analyzer': 'peliasAdmin', + 'admin:admin1:field': 'admin1', + 'admin:admin1:boost': 3, + + 'admin:admin1_abbr:analyzer': 'peliasAdmin', + 'admin:admin1_abbr:field': 'admin1_abbr', + 'admin:admin1_abbr:boost': 3, + + 'admin:admin2:analyzer': 'peliasAdmin', + 'admin:admin2:field': 'admin2', + 'admin:admin2:boost': 2, + + 'admin:local_admin:analyzer': 'peliasAdmin', + 'admin:local_admin:field': 'local_admin', + 'admin:local_admin:boost': 1, + + 'admin:locality:analyzer': 'peliasAdmin', + 'admin:locality:field': 'locality', + 'admin:locality:boost': 1, + + 'admin:neighborhood:analyzer': 'peliasAdmin', + 'admin:neighborhood:field': 'neighborhood', + 'admin:neighborhood:boost': 1, + + 'popularity:field': 'popularity', + 'popularity:modifier': 'log1p', + 'popularity:max_boost': 20, + 'popularity:weight': 1, + + 'population:field': 'population', + 'population:modifier': 'log1p', + 'population:max_boost': 20, + 'population:weight': 2 + +}); diff --git a/sanitiser/_geo_reverse.js b/sanitiser/_geo_reverse.js index c15af48b..52f2980f 100644 --- a/sanitiser/_geo_reverse.js +++ b/sanitiser/_geo_reverse.js @@ -1,7 +1,7 @@ var geo_common = require ('./_geo_common'); var _ = require('lodash'); -var defaults = require('../query/defaults'); +var defaults = require('../query/reverse_defaults'); var LAT_LON_IS_REQUIRED = true, CIRCLE_IS_REQUIRED = false; diff --git a/test/unit/query/autocomplete_defaults.js b/test/unit/query/autocomplete_defaults.js new file mode 100644 index 00000000..7ccb17a0 --- /dev/null +++ b/test/unit/query/autocomplete_defaults.js @@ -0,0 +1,22 @@ + +var defaults = require('../../../query/autocomplete_defaults'); + +module.exports.tests = {}; + +module.exports.tests.interface = function(test, common) { + test('valid interface', function(t) { + t.equal(typeof defaults, 'object', 'defaults defined'); + t.end(); + }); +}; + +module.exports.all = function (tape, common) { + + function test(name, testFunction) { + return tape('autocomplete defaults ' + name, testFunction); + } + + for( var testCase in module.exports.tests ){ + module.exports.tests[testCase](test, common); + } +}; diff --git a/test/unit/query/reverse_defaults.js b/test/unit/query/reverse_defaults.js new file mode 100644 index 00000000..48a9805f --- /dev/null +++ b/test/unit/query/reverse_defaults.js @@ -0,0 +1,22 @@ + +var defaults = require('../../../query/reverse_defaults'); + +module.exports.tests = {}; + +module.exports.tests.interface = function(test, common) { + test('valid interface', function(t) { + t.equal(typeof defaults, 'object', 'defaults defined'); + t.end(); + }); +}; + +module.exports.all = function (tape, common) { + + function test(name, testFunction) { + return tape('reverse defaults ' + name, testFunction); + } + + for( var testCase in module.exports.tests ){ + module.exports.tests[testCase](test, common); + } +}; diff --git a/test/unit/query/defaults.js b/test/unit/query/search_defaults.js similarity index 77% rename from test/unit/query/defaults.js rename to test/unit/query/search_defaults.js index d6fcc720..54b116b7 100644 --- a/test/unit/query/defaults.js +++ b/test/unit/query/search_defaults.js @@ -1,5 +1,5 @@ -var defaults = require('../../../query/defaults'); +var defaults = require('../../../query/search_defaults'); module.exports.tests = {}; @@ -13,7 +13,7 @@ module.exports.tests.interface = function(test, common) { module.exports.all = function (tape, common) { function test(name, testFunction) { - return tape('query defaults ' + name, testFunction); + return tape('search defaults ' + name, testFunction); } for( var testCase in module.exports.tests ){ diff --git a/test/unit/run.js b/test/unit/run.js index b79f9aca..76a3a437 100644 --- a/test/unit/run.js +++ b/test/unit/run.js @@ -16,7 +16,9 @@ var tests = [ require('./middleware/confidenceScoreReverse'), require('./middleware/distance'), require('./query/autocomplete'), - require('./query/defaults'), + require('./query/autocomplete_defaults'), + require('./query/search_defaults'), + require('./query/reverse_defaults'), require('./query/reverse'), require('./query/search'), require('./sanitiser/_boundary_country'), diff --git a/test/unit/sanitiser/_geo_reverse.js b/test/unit/sanitiser/_geo_reverse.js index e03e7ddd..e7c62e07 100644 --- a/test/unit/sanitiser/_geo_reverse.js +++ b/test/unit/sanitiser/_geo_reverse.js @@ -1,5 +1,5 @@ var sanitize = require('../../../sanitiser/_geo_reverse'); -var defaults = require('../../../query/defaults'); +var defaults = require('../../../query/reverse_defaults'); module.exports.tests = {}; diff --git a/test/unit/sanitiser/reverse.js b/test/unit/sanitiser/reverse.js index b92896e7..4e727b5b 100644 --- a/test/unit/sanitiser/reverse.js +++ b/test/unit/sanitiser/reverse.js @@ -4,7 +4,7 @@ var reverse = require('../../../sanitiser/reverse'), sanitize = reverse.sanitize, middleware = reverse.middleware, - defaults = require('../../../query/defaults'), + defaults = require('../../../query/reverse_defaults'), defaultError = 'missing param \'lat\'', defaultClean = { 'point.lat': 0, 'point.lon': 0,