diff --git a/query/autocomplete.js b/query/autocomplete.js index b3328a69..405fe486 100644 --- a/query/autocomplete.js +++ b/query/autocomplete.js @@ -1,5 +1,6 @@ -var peliasQuery = require('pelias-query'); +var peliasQuery = require('pelias-query'), + defaults = require('./defaults'); //------------------------------ // autocomplete query @@ -21,7 +22,7 @@ query.score( peliasQuery.view.focus ); **/ function generateQuery( clean ){ - var vs = new peliasQuery.Vars( peliasQuery.defaults ); + var vs = new peliasQuery.Vars( defaults ); // input text vs.var( 'input:name', clean.text ); diff --git a/query/defaults.js b/query/defaults.js new file mode 100644 index 00000000..cf9422d0 --- /dev/null +++ b/query/defaults.js @@ -0,0 +1,84 @@ + +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, + + 'function_score:score_mode': 'avg', + 'function_score:boost_mode': 'replace', + + 'address:housenumber:analyzer': 'standard', + 'address:housenumber:field': 'address.number', + 'address:housenumber:boost': 1, + + 'address:street:analyzer': 'standard', + 'address:street:field': 'address.street', + 'address:street:boost': 1, + + 'address:postcode:analyzer': 'standard', + 'address:postcode:field': 'address.zip', + 'address:postcode:boost': 1, + + 'admin:alpha3:analyzer': 'standard', + 'admin:alpha3:field': 'alpha3', + 'admin:alpha3:boost': 1, + + 'admin:admin0:analyzer': 'peliasAdmin', + 'admin:admin0:field': 'admin0', + 'admin:admin0:boost': 1, + + 'admin:admin1:analyzer': 'peliasAdmin', + 'admin:admin1:field': 'admin1', + 'admin:admin1:boost': 1, + + 'admin:admin1_abbr:analyzer': 'peliasAdmin', + 'admin:admin1_abbr:field': 'admin1_abbr', + 'admin:admin1_abbr:boost': 1, + + 'admin:admin2:analyzer': 'peliasAdmin', + 'admin:admin2:field': 'admin2', + 'admin:admin2:boost': 1, + + '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 + +}); \ No newline at end of file diff --git a/query/reverse.js b/query/reverse.js index bcf24755..8aca4d94 100644 --- a/query/reverse.js +++ b/query/reverse.js @@ -1,5 +1,6 @@ var peliasQuery = require('pelias-query'), + defaults = require('./defaults'), sort = require('./sort'); //------------------------------ @@ -17,7 +18,7 @@ query.filter( peliasQuery.view.boundary_circle ); function generateQuery( clean ){ - var vs = new peliasQuery.Vars( peliasQuery.defaults ); + var vs = new peliasQuery.Vars( defaults ); // set defaults vs.set({ diff --git a/query/search.js b/query/search.js index a0b65721..fa9b25d2 100644 --- a/query/search.js +++ b/query/search.js @@ -1,5 +1,6 @@ var peliasQuery = require('pelias-query'), + defaults = require('./defaults'), sort = require('../query/sort'), adminFields = require('../helper/adminFields')(); @@ -43,7 +44,7 @@ query.filter( peliasQuery.view.boundary_rect ); **/ function generateQuery( clean ){ - var vs = new peliasQuery.Vars( peliasQuery.defaults ); + var vs = new peliasQuery.Vars( defaults ); // input text vs.var( 'input:name', clean.text ); diff --git a/test/unit/query/defaults.js b/test/unit/query/defaults.js new file mode 100644 index 00000000..d6fcc720 --- /dev/null +++ b/test/unit/query/defaults.js @@ -0,0 +1,22 @@ + +var defaults = require('../../../query/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('query defaults ' + name, testFunction); + } + + for( var testCase in module.exports.tests ){ + module.exports.tests[testCase](test, common); + } +}; diff --git a/test/unit/run.js b/test/unit/run.js index 885efe5f..cfd99715 100644 --- a/test/unit/run.js +++ b/test/unit/run.js @@ -17,6 +17,7 @@ var tests = [ require('./query/search'), require('./query/autocomplete'), require('./query/reverse'), + require('./query/defaults'), require('./helper/query_parser'), require('./helper/geojsonify'), require('./helper/outputSchema'),