mirror of https://github.com/pelias/api.git
Julian Simioni
9 years ago
55 changed files with 1726 additions and 1416 deletions
@ -0,0 +1,5 @@
|
||||
#!/bin/bash |
||||
|
||||
set -euo pipefail |
||||
|
||||
node test/unit/run.js | ./node_modules/.bin/tap-dot |
@ -1,66 +1,73 @@
|
||||
var _ = require('lodash'), |
||||
check = require('check-types'); |
||||
var _ = require('lodash'); |
||||
|
||||
module.exports = { |
||||
'USA': { |
||||
'local': getFirstProperty(['borough', 'localadmin', 'locality', 'neighbourhood', 'county']), |
||||
'regional': getUsState, |
||||
'country': getFirstProperty(['country_a']) |
||||
'default': { |
||||
'local': getFirstProperty(['locality', 'localadmin']), |
||||
'country': getFirstProperty(['country']) |
||||
}, |
||||
'GBR': { |
||||
'local': getFirstProperty(['neighbourhood', 'county', 'localadmin', 'locality', 'macroregion', 'region']), |
||||
'regional': getFirstProperty(['county','country','region']) |
||||
}, |
||||
'SGP': { |
||||
'local': getFirstProperty(['neighbourhood', 'region', 'county', 'localadmin', 'locality']), |
||||
'regional': getFirstProperty(['county','country','region']) |
||||
'local': getFirstProperty(['locality', 'localadmin']), |
||||
'regional': getFirstProperty(['macroregion']), |
||||
'country': getFirstProperty(['country']) |
||||
}, |
||||
'SWE': { |
||||
'local': getFirstProperty(['neighbourhood', 'region', 'county', 'localadmin', 'locality']), |
||||
'regional': getFirstProperty(['country']) |
||||
'USA': { |
||||
'borough': getFirstProperty(['borough']), |
||||
'local': getFirstProperty(['locality', 'localadmin']), |
||||
'regional': getUsOrCaState, |
||||
'country': getUSACountryValue |
||||
}, |
||||
'default': { |
||||
'local': getFirstProperty(['localadmin', 'locality', 'neighbourhood', 'county', 'macroregion', 'region']), |
||||
'regional': getFirstProperty(['country']) |
||||
'CAN': { |
||||
'local': getFirstProperty(['locality']), // no localadmins in CAN
|
||||
'regional': getUsOrCaState, |
||||
'country': getFirstProperty(['country']) |
||||
} |
||||
}; |
||||
|
||||
// find the first field of record that has a non-empty value that's not already in labelParts
|
||||
function getFirstProperty(fields) { |
||||
return function(record, labelParts) { |
||||
return function(record) { |
||||
for (var i = 0; i < fields.length; i++) { |
||||
var fieldValue = record[fields[i]]; |
||||
|
||||
if (check.nonEmptyString(fieldValue) && !_.includes(labelParts, fieldValue)) { |
||||
labelParts.push( fieldValue ); |
||||
return labelParts; |
||||
if (!_.isEmpty(fieldValue)) { |
||||
return fieldValue; |
||||
} |
||||
|
||||
} |
||||
|
||||
return labelParts; |
||||
|
||||
}; |
||||
|
||||
} |
||||
|
||||
// this function is exclusively used for figuring out which field to use for US States
|
||||
// 1. if a US state is the most granular bit of info entered, the label should contain
|
||||
// the full state name, eg: Pennsylvania, USA
|
||||
// 2. otherwise, the state abbreviation should be used, eg: Lancaster, PA, USA
|
||||
// this function is exclusively used for figuring out which field to use for US/CA States
|
||||
// 1. if a US/CA state is the most granular bit of info entered, the label should contain
|
||||
// the full state name, eg: Pennsylvania, USA and Ontario, CA
|
||||
// 2. otherwise, the state abbreviation should be used, eg: Lancaster, PA, USA and Bruce, ON, CA
|
||||
// 3. if for some reason the abbreviation isn't available, use the full state name
|
||||
function getUsState(record, labelParts) { |
||||
function getUsOrCaState(record) { |
||||
if ('region' === record.layer && record.region) { |
||||
// add full state name when state is the most granular piece of info
|
||||
labelParts.push(record.region); |
||||
// return full state name when state is the most granular piece of info
|
||||
return record.region; |
||||
|
||||
} else if (record.region_a) { |
||||
// otherwise just add the region code when available
|
||||
labelParts.push(record.region_a); |
||||
// otherwise just return the region code when available
|
||||
return record.region_a; |
||||
|
||||
} else if (record.region) { |
||||
// add the full name when there's no region code available ()
|
||||
labelParts.push(record.region); |
||||
// return the full name when there's no region code available
|
||||
return record.region; |
||||
|
||||
} |
||||
|
||||
return labelParts; |
||||
} |
||||
|
||||
// this function returns the full name of a country if the result is in the
|
||||
// country layer (for "United States" record). It returns the abbreviation
|
||||
// otherwise (eg - Lancaster, PA, USA).
|
||||
function getUSACountryValue(record) { |
||||
if ('country' === record.layer && record.country) { |
||||
return record.country; |
||||
} |
||||
|
||||
return record.country_a; |
||||
} |
||||
|
@ -0,0 +1,34 @@
|
||||
|
||||
#> layer alias |
||||
path: '/v1/autocomplete?text=a&layers=address' |
||||
|
||||
#? 200 ok |
||||
response.statusCode.should.be.equal 200 |
||||
response.should.have.header 'charset', 'utf8' |
||||
response.should.have.header 'content-type', 'application/json; charset=utf-8' |
||||
|
||||
#? valid geocoding block |
||||
should.exist json.geocoding |
||||
should.exist json.geocoding.version |
||||
should.exist json.geocoding.attribution |
||||
should.exist json.geocoding.query |
||||
should.exist json.geocoding.engine |
||||
should.exist json.geocoding.engine.name |
||||
should.exist json.geocoding.engine.author |
||||
should.exist json.geocoding.engine.version |
||||
should.exist json.geocoding.timestamp |
||||
|
||||
#? valid geojson |
||||
json.type.should.be.equal 'FeatureCollection' |
||||
json.features.should.be.instanceof Array |
||||
|
||||
#? expected errors |
||||
should.not.exist json.geocoding.errors |
||||
|
||||
#? expected warnings |
||||
should.not.exist json.geocoding.warnings |
||||
|
||||
#? inputs |
||||
json.geocoding.query['text'].should.eql 'a' |
||||
json.geocoding.query['size'].should.eql 10 |
||||
json.geocoding.query.layers.should.eql ["address"] |
@ -0,0 +1,47 @@
|
||||
|
||||
#> layer alias |
||||
path: '/v1/autocomplete?text=a&layers=coarse' |
||||
|
||||
#? 200 ok |
||||
response.statusCode.should.be.equal 200 |
||||
response.should.have.header 'charset', 'utf8' |
||||
response.should.have.header 'content-type', 'application/json; charset=utf-8' |
||||
|
||||
#? valid geocoding block |
||||
should.exist json.geocoding |
||||
should.exist json.geocoding.version |
||||
should.exist json.geocoding.attribution |
||||
should.exist json.geocoding.query |
||||
should.exist json.geocoding.engine |
||||
should.exist json.geocoding.engine.name |
||||
should.exist json.geocoding.engine.author |
||||
should.exist json.geocoding.engine.version |
||||
should.exist json.geocoding.timestamp |
||||
|
||||
#? valid geojson |
||||
json.type.should.be.equal 'FeatureCollection' |
||||
json.features.should.be.instanceof Array |
||||
|
||||
#? expected errors |
||||
should.not.exist json.geocoding.errors |
||||
|
||||
#? expected warnings |
||||
should.not.exist json.geocoding.warnings |
||||
|
||||
#? inputs |
||||
json.geocoding.query['text'].should.eql 'a' |
||||
json.geocoding.query['size'].should.eql 10 |
||||
json.geocoding.query.layers.should.eql [ "continent", |
||||
"country", |
||||
"dependency", |
||||
"macroregion", |
||||
"region", |
||||
"locality", |
||||
"localadmin", |
||||
"macrocounty", |
||||
"county", |
||||
"macrohood", |
||||
"neighbourhood", |
||||
"microhood", |
||||
"disputed" |
||||
] |
@ -0,0 +1,34 @@
|
||||
|
||||
#> layer alias |
||||
path: '/v1/autocomplete?text=a&layers=notlayer' |
||||
|
||||
#? 200 ok |
||||
response.statusCode.should.be.equal 400 |
||||
response.should.have.header 'charset', 'utf8' |
||||
response.should.have.header 'content-type', 'application/json; charset=utf-8' |
||||
|
||||
#? valid geocoding block |
||||
should.exist json.geocoding |
||||
should.exist json.geocoding.version |
||||
should.exist json.geocoding.attribution |
||||
should.exist json.geocoding.query |
||||
should.exist json.geocoding.engine |
||||
should.exist json.geocoding.engine.name |
||||
should.exist json.geocoding.engine.author |
||||
should.exist json.geocoding.engine.version |
||||
should.exist json.geocoding.timestamp |
||||
|
||||
#? valid geojson |
||||
json.type.should.be.equal 'FeatureCollection' |
||||
json.features.should.be.instanceof Array |
||||
|
||||
#? expected errors |
||||
should.exist json.geocoding.errors |
||||
json.geocoding.errors.should.eql [ '\'notlayer\' is an invalid layers parameter. Valid options: coarse,address,venue,country,macroregion,region,county,locality,continent,macrocounty,dependency,localadmin,macrohood,neighbourhood,microhood,disputed' ] |
||||
|
||||
#? expected warnings |
||||
should.not.exist json.geocoding.warnings |
||||
|
||||
#? inputs |
||||
json.geocoding.query['text'].should.eql 'a' |
||||
json.geocoding.query['size'].should.eql 10 |
@ -0,0 +1,35 @@
|
||||
|
||||
#> layer alias |
||||
path: '/v1/autocomplete?text=a&layers=country,notlayer' |
||||
|
||||
#? 200 ok |
||||
response.statusCode.should.be.equal 400 |
||||
response.should.have.header 'charset', 'utf8' |
||||
response.should.have.header 'content-type', 'application/json; charset=utf-8' |
||||
|
||||
#? valid geocoding block |
||||
should.exist json.geocoding |
||||
should.exist json.geocoding.version |
||||
should.exist json.geocoding.attribution |
||||
should.exist json.geocoding.query |
||||
should.exist json.geocoding.engine |
||||
should.exist json.geocoding.engine.name |
||||
should.exist json.geocoding.engine.author |
||||
should.exist json.geocoding.engine.version |
||||
should.exist json.geocoding.timestamp |
||||
|
||||
#? valid geojson |
||||
json.type.should.be.equal 'FeatureCollection' |
||||
json.features.should.be.instanceof Array |
||||
|
||||
#? expected errors |
||||
should.exist json.geocoding.errors |
||||
json.geocoding.errors.should.eql [ '\'notlayer\' is an invalid layers parameter. Valid options: coarse,address,venue,country,macroregion,region,county,locality,continent,macrocounty,dependency,localadmin,macrohood,neighbourhood,microhood,disputed' ] |
||||
|
||||
#? expected warnings |
||||
should.not.exist json.geocoding.warnings |
||||
|
||||
#? inputs |
||||
json.geocoding.query['text'].should.eql 'a' |
||||
json.geocoding.query['size'].should.eql 10 |
||||
should.not.exist json.geocoding.query['layers'] |
@ -0,0 +1,34 @@
|
||||
|
||||
#> layer alias |
||||
path: '/v1/autocomplete?text=a&layers=country,region' |
||||
|
||||
#? 200 ok |
||||
response.statusCode.should.be.equal 200 |
||||
response.should.have.header 'charset', 'utf8' |
||||
response.should.have.header 'content-type', 'application/json; charset=utf-8' |
||||
|
||||
#? valid geocoding block |
||||
should.exist json.geocoding |
||||
should.exist json.geocoding.version |
||||
should.exist json.geocoding.attribution |
||||
should.exist json.geocoding.query |
||||
should.exist json.geocoding.engine |
||||
should.exist json.geocoding.engine.name |
||||
should.exist json.geocoding.engine.author |
||||
should.exist json.geocoding.engine.version |
||||
should.exist json.geocoding.timestamp |
||||
|
||||
#? valid geojson |
||||
json.type.should.be.equal 'FeatureCollection' |
||||
json.features.should.be.instanceof Array |
||||
|
||||
#? expected errors |
||||
should.not.exist json.geocoding.errors |
||||
|
||||
#? expected warnings |
||||
should.not.exist json.geocoding.warnings |
||||
|
||||
#? inputs |
||||
json.geocoding.query['text'].should.eql 'a' |
||||
json.geocoding.query['size'].should.eql 10 |
||||
json.geocoding.query.layers.should.eql ["country","region"] |
@ -0,0 +1,34 @@
|
||||
|
||||
#> layer alias |
||||
path: '/v1/autocomplete?text=a&layers=country' |
||||
|
||||
#? 200 ok |
||||
response.statusCode.should.be.equal 200 |
||||
response.should.have.header 'charset', 'utf8' |
||||
response.should.have.header 'content-type', 'application/json; charset=utf-8' |
||||
|
||||
#? valid geocoding block |
||||
should.exist json.geocoding |
||||
should.exist json.geocoding.version |
||||
should.exist json.geocoding.attribution |
||||
should.exist json.geocoding.query |
||||
should.exist json.geocoding.engine |
||||
should.exist json.geocoding.engine.name |
||||
should.exist json.geocoding.engine.author |
||||
should.exist json.geocoding.engine.version |
||||
should.exist json.geocoding.timestamp |
||||
|
||||
#? valid geojson |
||||
json.type.should.be.equal 'FeatureCollection' |
||||
json.features.should.be.instanceof Array |
||||
|
||||
#? expected errors |
||||
should.not.exist json.geocoding.errors |
||||
|
||||
#? expected warnings |
||||
should.not.exist json.geocoding.warnings |
||||
|
||||
#? inputs |
||||
json.geocoding.query['text'].should.eql 'a' |
||||
json.geocoding.query['size'].should.eql 10 |
||||
json.geocoding.query.layers.should.eql ["country"] |
@ -0,0 +1,34 @@
|
||||
|
||||
#> set size (autocomplete does not allow size to be changed) |
||||
path: '/v1/autocomplete?text=a&size=3' |
||||
|
||||
#? 200 ok |
||||
response.statusCode.should.be.equal 200 |
||||
response.should.have.header 'charset', 'utf8' |
||||
response.should.have.header 'content-type', 'application/json; charset=utf-8' |
||||
|
||||
#? valid geocoding block |
||||
should.exist json.geocoding |
||||
should.exist json.geocoding.version |
||||
should.exist json.geocoding.attribution |
||||
should.exist json.geocoding.query |
||||
should.exist json.geocoding.engine |
||||
should.exist json.geocoding.engine.name |
||||
should.exist json.geocoding.engine.author |
||||
should.exist json.geocoding.engine.version |
||||
should.exist json.geocoding.timestamp |
||||
|
||||
#? valid geojson |
||||
json.type.should.be.equal 'FeatureCollection' |
||||
json.features.should.be.instanceof Array |
||||
|
||||
#? expected errors |
||||
should.not.exist json.geocoding.errors |
||||
|
||||
#? expected warnings |
||||
should.exist json.geocoding.warnings |
||||
json.geocoding.warnings.should.eql [ 'out-of-range integer \'size\', using MIN_SIZE' ] |
||||
|
||||
#? inputs |
||||
json.geocoding.query['text'].should.eql 'a' |
||||
json.geocoding.query['size'].should.eql 10 # should remain the default size |
@ -0,0 +1,34 @@
|
||||
|
||||
#> sources filter |
||||
path: '/v1/autocomplete?text=a&sources=openstreetmap,notasource' |
||||
|
||||
#? 200 ok |
||||
response.statusCode.should.be.equal 400 |
||||
response.should.have.header 'charset', 'utf8' |
||||
response.should.have.header 'content-type', 'application/json; charset=utf-8' |
||||
|
||||
#? valid geocoding block |
||||
should.exist json.geocoding |
||||
should.exist json.geocoding.version |
||||
should.exist json.geocoding.attribution |
||||
should.exist json.geocoding.query |
||||
should.exist json.geocoding.engine |
||||
should.exist json.geocoding.engine.name |
||||
should.exist json.geocoding.engine.author |
||||
should.exist json.geocoding.engine.version |
||||
should.exist json.geocoding.timestamp |
||||
|
||||
#? valid geojson |
||||
json.type.should.be.equal 'FeatureCollection' |
||||
json.features.should.be.instanceof Array |
||||
|
||||
#? expected errors |
||||
should.exist json.geocoding.errors |
||||
json.geocoding.errors.should.eql [ '\'notasource\' is an invalid sources parameter. Valid options: osm,oa,gn,wof,openstreetmap,openaddresses,geonames,whosonfirst' ] |
||||
|
||||
#? expected warnings |
||||
should.not.exist json.geocoding.warnings |
||||
|
||||
#? inputs |
||||
json.geocoding.query['text'].should.eql 'a' |
||||
json.geocoding.query['size'].should.eql 10 |
@ -0,0 +1,37 @@
|
||||
|
||||
#> sources and layers specified (invalid combo) |
||||
path: '/v1/autocomplete?text=a&sources=whosonfirst&layers=address' |
||||
|
||||
#? 200 ok |
||||
response.statusCode.should.be.equal 400 |
||||
response.should.have.header 'charset', 'utf8' |
||||
response.should.have.header 'content-type', 'application/json; charset=utf-8' |
||||
|
||||
#? valid geocoding block |
||||
should.exist json.geocoding |
||||
should.exist json.geocoding.version |
||||
should.exist json.geocoding.attribution |
||||
should.exist json.geocoding.query |
||||
should.exist json.geocoding.engine |
||||
should.exist json.geocoding.engine.name |
||||
should.exist json.geocoding.engine.author |
||||
should.exist json.geocoding.engine.version |
||||
should.exist json.geocoding.timestamp |
||||
|
||||
#? valid geojson |
||||
json.type.should.be.equal 'FeatureCollection' |
||||
json.features.should.be.instanceof Array |
||||
|
||||
#? expected errors |
||||
should.exist json.geocoding.errors |
||||
json.geocoding.errors.should.eql [ 'You have specified both the `sources` and `layers` parameters in a combination that will return no results: the whosonfirst source has nothing in the address layer' ] |
||||
|
||||
#? expected warnings |
||||
should.not.exist json.geocoding.warnings |
||||
|
||||
#? inputs |
||||
json.geocoding.query['text'].should.eql 'a' |
||||
json.geocoding.query['size'].should.eql 10 |
||||
json.geocoding.query.layers.should.eql ["address"] |
||||
json.geocoding.query.sources.should.eql ["whosonfirst"] |
||||
should.not.exist json.geocoding.query['type'] |
@ -0,0 +1,35 @@
|
||||
|
||||
#> sources and layers specified |
||||
path: '/v1/autocomplete?text=a&sources=openaddresses&layers=address' |
||||
|
||||
#? 200 ok |
||||
response.statusCode.should.be.equal 200 |
||||
response.should.have.header 'charset', 'utf8' |
||||
response.should.have.header 'content-type', 'application/json; charset=utf-8' |
||||
|
||||
#? valid geocoding block |
||||
should.exist json.geocoding |
||||
should.exist json.geocoding.version |
||||
should.exist json.geocoding.attribution |
||||
should.exist json.geocoding.query |
||||
should.exist json.geocoding.engine |
||||
should.exist json.geocoding.engine.name |
||||
should.exist json.geocoding.engine.author |
||||
should.exist json.geocoding.engine.version |
||||
should.exist json.geocoding.timestamp |
||||
|
||||
#? valid geojson |
||||
json.type.should.be.equal 'FeatureCollection' |
||||
json.features.should.be.instanceof Array |
||||
|
||||
#? expected errors |
||||
should.not.exist json.geocoding.errors |
||||
|
||||
#? expected warnings |
||||
should.not.exist json.geocoding.warnings |
||||
|
||||
#? inputs |
||||
json.geocoding.query['text'].should.eql 'a' |
||||
json.geocoding.query['size'].should.eql 10 |
||||
json.geocoding.query.layers.should.eql ["address"] |
||||
json.geocoding.query.sources.should.eql ["openaddresses"] |
@ -0,0 +1,34 @@
|
||||
|
||||
#> sources filter |
||||
path: "/v1/autocomplete?text=a&sources=openstreetmap,geonames" |
||||
|
||||
#? 200 ok |
||||
response.statusCode.should.be.equal 200 |
||||
response.should.have.header "charset", 'utf8' |
||||
response.should.have.header 'content-type', 'application/json; charset=utf-8' |
||||
|
||||
#? valid geocoding block |
||||
should.exist json.geocoding |
||||
should.exist json.geocoding.version |
||||
should.exist json.geocoding.attribution |
||||
should.exist json.geocoding.query |
||||
should.exist json.geocoding.engine |
||||
should.exist json.geocoding.engine.name |
||||
should.exist json.geocoding.engine.author |
||||
should.exist json.geocoding.engine.version |
||||
should.exist json.geocoding.timestamp |
||||
|
||||
#? valid geojson |
||||
json.type.should.be.equal 'FeatureCollection' |
||||
json.features.should.be.instanceof Array |
||||
|
||||
#? expected errors |
||||
should.not.exist json.geocoding.errors |
||||
|
||||
#? expected warnings |
||||
should.not.exist json.geocoding.warnings |
||||
|
||||
#? inputs |
||||
json.geocoding.query['text'].should.eql 'a' |
||||
json.geocoding.query['size'].should.eql 10 |
||||
json.geocoding.query.sources.should.eql ["openstreetmap", "geonames"] |
@ -0,0 +1,34 @@
|
||||
|
||||
#> sources filter |
||||
path: '/v1/autocomplete?text=a&sources=openstreetmap' |
||||
|
||||
#? 200 ok |
||||
response.statusCode.should.be.equal 200 |
||||
response.should.have.header 'charset', 'utf8' |
||||
response.should.have.header 'content-type', 'application/json; charset=utf-8' |
||||
|
||||
#? valid geocoding block |
||||
should.exist json.geocoding |
||||
should.exist json.geocoding.version |
||||
should.exist json.geocoding.attribution |
||||
should.exist json.geocoding.query |
||||
should.exist json.geocoding.engine |
||||
should.exist json.geocoding.engine.name |
||||
should.exist json.geocoding.engine.author |
||||
should.exist json.geocoding.engine.version |
||||
should.exist json.geocoding.timestamp |
||||
|
||||
#? valid geojson |
||||
json.type.should.be.equal 'FeatureCollection' |
||||
json.features.should.be.instanceof Array |
||||
|
||||
#? expected errors |
||||
should.not.exist json.geocoding.errors |
||||
|
||||
#? expected warnings |
||||
should.not.exist json.geocoding.warnings |
||||
|
||||
#? inputs |
||||
json.geocoding.query['text'].should.eql 'a' |
||||
json.geocoding.query['size'].should.eql 10 |
||||
json.geocoding.query.sources.should.eql ["openstreetmap"] |
@ -0,0 +1,58 @@
|
||||
|
||||
/** |
||||
Test data required by the ciao test suite. |
||||
|
||||
Some tests will fail when run against an empty index, you can use this script |
||||
to insert some dummy data in to your index before running the tests. |
||||
|
||||
note: as this is dummy data, care should be taken in order to make sure these |
||||
documents don't end up in your production index; for that reason the HTTP port |
||||
has been hard-coded as port:9200. |
||||
**/ |
||||
|
||||
// we use the default config to avoid making calls to
|
||||
// a cluster running on a non-standard port.
|
||||
var client = require('elasticsearch').Client(), |
||||
async = require('async'), |
||||
actions = []; |
||||
|
||||
// add one record per 'type' in order to cause the _default_ mapping
|
||||
// to be copied when the new type is created.
|
||||
var types = ['venue','address','county','region','county','country','admin0','admin1','admin2'], |
||||
sources = ['test'], |
||||
layers = ['geonames']; |
||||
|
||||
// iterate over all types/sources/layers and index a test document
|
||||
types.forEach( function( type, i1 ){ |
||||
sources.forEach( function( source, i2 ){ |
||||
layers.forEach( function( layer, i3 ){ |
||||
actions.push( function( done ){ |
||||
client.index({ |
||||
index: 'pelias', |
||||
type: type, |
||||
id: [i1,i2,i3].join(':'), |
||||
body: { |
||||
source: source, |
||||
layer: layer, |
||||
name: { default: 'test' }, |
||||
phrase: { default: 'test' }, |
||||
parent: { |
||||
country_a: ['USA'] |
||||
} |
||||
} |
||||
}); |
||||
done(); |
||||
}); |
||||
}); |
||||
}); |
||||
}); |
||||
|
||||
// call refresh so the index merges the changes
|
||||
actions.push( function( done ){ |
||||
client.indices.refresh( { index: 'pelias' }, done); |
||||
}); |
||||
|
||||
// perform all actions in series
|
||||
async.series( actions, function( err, resp ){ |
||||
console.log('test data inported'); |
||||
}); |
@ -0,0 +1,85 @@
|
||||
|
||||
module.exports = { |
||||
'query': { |
||||
'filtered': { |
||||
'query': { |
||||
'bool': { |
||||
'must': [{ |
||||
'match': { |
||||
'name.default': { |
||||
'analyzer': 'peliasPhrase', |
||||
'boost': 100, |
||||
'query': 'test', |
||||
'type': 'phrase', |
||||
'operator': 'and' |
||||
} |
||||
} |
||||
}], |
||||
'should':[{ |
||||
'function_score': { |
||||
'query': { |
||||
'match': { |
||||
'name.default': { |
||||
'analyzer': 'peliasPhrase', |
||||
'boost': 100, |
||||
'query': 'test', |
||||
'type': 'phrase', |
||||
'operator': 'and' |
||||
} |
||||
} |
||||
}, |
||||
'max_boost': 20, |
||||
'score_mode': 'first', |
||||
'boost_mode': 'replace', |
||||
'functions': [{ |
||||
'field_value_factor': { |
||||
'modifier': 'log1p', |
||||
'field': 'popularity', |
||||
'missing': 1 |
||||
}, |
||||
'weight': 1 |
||||
}] |
||||
} |
||||
},{ |
||||
'function_score': { |
||||
'query': { |
||||
'match': { |
||||
'name.default': { |
||||
'analyzer': 'peliasPhrase', |
||||
'boost': 100, |
||||
'query': 'test', |
||||
'type': 'phrase', |
||||
'operator': 'and' |
||||
} |
||||
} |
||||
}, |
||||
'max_boost': 20, |
||||
'score_mode': 'first', |
||||
'boost_mode': 'replace', |
||||
'functions': [{ |
||||
'field_value_factor': { |
||||
'modifier': 'log1p', |
||||
'field': 'population', |
||||
'missing': 1 |
||||
}, |
||||
'weight': 3 |
||||
}] |
||||
} |
||||
}] |
||||
} |
||||
}, |
||||
'filter': { |
||||
'bool': { |
||||
'must': [{ |
||||
'terms': { |
||||
'source': ['test_source'] |
||||
} |
||||
}] |
||||
} |
||||
} |
||||
} |
||||
}, |
||||
'sort': [ '_score' ], |
||||
'size': 20, |
||||
'track_scores': true |
||||
}; |
@ -0,0 +1,93 @@
|
||||
|
||||
module.exports = { |
||||
'query': { |
||||
'filtered': { |
||||
'query': { |
||||
'bool': { |
||||
'must': [{ |
||||
'match': { |
||||
'name.default': { |
||||
'query': 'test', |
||||
'boost': 1, |
||||
'analyzer': 'peliasOneEdgeGram' |
||||
} |
||||
} |
||||
}], |
||||
'should': [{ |
||||
'match': { |
||||
'phrase.default': { |
||||
'query': 'test', |
||||
'analyzer': 'peliasPhrase', |
||||
'type': 'phrase', |
||||
'boost': 1, |
||||
'slop': 2 |
||||
} |
||||
} |
||||
},{ |
||||
'function_score': { |
||||
'query': { |
||||
'match': { |
||||
'phrase.default': { |
||||
'query': 'test', |
||||
'analyzer': 'peliasPhrase', |
||||
'type': 'phrase', |
||||
'slop': 2, |
||||
'boost': 1 |
||||
} |
||||
} |
||||
}, |
||||
'max_boost': 20, |
||||
'score_mode': 'first', |
||||
'boost_mode': 'replace', |
||||
'functions': [{ |
||||
'field_value_factor': { |
||||
'modifier': 'log1p', |
||||
'field': 'popularity', |
||||
'missing': 1 |
||||
}, |
||||
'weight': 1 |
||||
}] |
||||
} |
||||
},{ |
||||
'function_score': { |
||||
'query': { |
||||
'match': { |
||||
'phrase.default': { |
||||
'query': 'test', |
||||
'analyzer': 'peliasPhrase', |
||||
'type': 'phrase', |
||||
'slop': 2, |
||||
'boost': 1 |
||||
} |
||||
} |
||||
}, |
||||
'max_boost': 20, |
||||
'score_mode': 'first', |
||||
'boost_mode': 'replace', |
||||
'functions': [{ |
||||
'field_value_factor': { |
||||
'modifier': 'log1p', |
||||
'field': 'population', |
||||
'missing': 1 |
||||
}, |
||||
'weight': 2 |
||||
}] |
||||
} |
||||
}] |
||||
} |
||||
}, |
||||
'filter': { |
||||
'bool': { |
||||
'must': [{ |
||||
'terms': { |
||||
'source': ['test_source'] |
||||
} |
||||
}] |
||||
} |
||||
} |
||||
} |
||||
}, |
||||
'sort': [ '_score' ], |
||||
'size': 20, |
||||
'track_scores': true |
||||
}; |
@ -0,0 +1,205 @@
|
||||
var generator = require('../../../helper/labelGenerator'); |
||||
|
||||
module.exports.tests = {}; |
||||
|
||||
module.exports.tests.interface = function(test, common) { |
||||
test('interface', function(t) { |
||||
t.equal(typeof generator, 'function', 'valid function'); |
||||
t.end(); |
||||
}); |
||||
}; |
||||
|
||||
module.exports.tests.canada = function(test, common) { |
||||
test('venue', function(t) { |
||||
var doc = { |
||||
'name': 'venue name', |
||||
'layer': 'venue', |
||||
'housenumber': 'house number', |
||||
'street': 'street name', |
||||
'neighbourhood': 'neighbourhood name', |
||||
'locality': 'locality name', |
||||
'localadmin': 'localadmin name', |
||||
'county': 'county name', |
||||
'macrocounty': 'macrocounty name', |
||||
'region_a': 'region abbr', |
||||
'region': 'region name', |
||||
'macroregion': 'macroregion name', |
||||
'country_a': 'CAN', |
||||
'country': 'Canada' |
||||
}; |
||||
t.equal(generator(doc),'venue name, locality name, region abbr, Canada'); |
||||
t.end(); |
||||
}); |
||||
|
||||
test('street', function(t) { |
||||
var doc = { |
||||
'name': 'house number street name', |
||||
'layer': 'address', |
||||
'housenumber': 'house number', |
||||
'street': 'street name', |
||||
'neighbourhood': 'neighbourhood name', |
||||
'locality': 'locality name', |
||||
'localadmin': 'localadmin name', |
||||
'county': 'county name', |
||||
'macrocounty': 'macrocounty name', |
||||
'region_a': 'region abbr', |
||||
'region': 'region name', |
||||
'macroregion': 'macroregion name', |
||||
'country_a': 'CAN', |
||||
'country': 'Canada' |
||||
}; |
||||
t.equal(generator(doc),'house number street name, locality name, region abbr, Canada'); |
||||
t.end(); |
||||
}); |
||||
|
||||
test('neighbourhood', function(t) { |
||||
var doc = { |
||||
'name': 'neighbourhood name', |
||||
'layer': 'neighbourhood', |
||||
'neighbourhood': 'neighbourhood name', |
||||
'locality': 'locality name', |
||||
'localadmin': 'localadmin name', |
||||
'county': 'county name', |
||||
'macrocounty': 'macrocounty name', |
||||
'region_a': 'region abbr', |
||||
'region': 'region name', |
||||
'macroregion': 'macroregion name', |
||||
'country_a': 'CAN', |
||||
'country': 'Canada' |
||||
}; |
||||
t.equal(generator(doc),'neighbourhood name, locality name, region abbr, Canada'); |
||||
t.end(); |
||||
}); |
||||
|
||||
test('locality', function(t) { |
||||
var doc = { |
||||
'name': 'locality name', |
||||
'layer': 'locality', |
||||
'locality': 'locality name', |
||||
'localadmin': 'localadmin name', |
||||
'county': 'county name', |
||||
'macrocounty': 'macrocounty name', |
||||
'region_a': 'region abbr', |
||||
'region': 'region name', |
||||
'macroregion': 'macroregion name', |
||||
'country_a': 'CAN', |
||||
'country': 'Canada' |
||||
}; |
||||
t.equal(generator(doc),'locality name, region abbr, Canada'); |
||||
t.end(); |
||||
}); |
||||
|
||||
test('localadmin', function(t) { |
||||
var doc = { |
||||
'name': 'localadmin name', |
||||
'layer': 'localadmin', |
||||
'localadmin': 'localadmin name', |
||||
'county': 'county name', |
||||
'macrocounty': 'macrocounty name', |
||||
'region_a': 'region abbr', |
||||
'region': 'region name', |
||||
'macroregion': 'macroregion name', |
||||
'country_a': 'CAN', |
||||
'country': 'Canada' |
||||
}; |
||||
t.equal(generator(doc),'localadmin name, region abbr, Canada'); |
||||
t.end(); |
||||
}); |
||||
|
||||
test('county', function(t) { |
||||
var doc = { |
||||
'name': 'county name', |
||||
'layer': 'county', |
||||
'county': 'county name', |
||||
'macrocounty': 'macrocounty name', |
||||
'region_a': 'region abbr', |
||||
'region': 'region name', |
||||
'macroregion': 'macroregion name', |
||||
'country_a': 'CAN', |
||||
'country': 'Canada' |
||||
}; |
||||
t.equal(generator(doc),'county name, region abbr, Canada'); |
||||
t.end(); |
||||
}); |
||||
|
||||
test('macrocounty', function(t) { |
||||
var doc = { |
||||
'name': 'macrocounty name', |
||||
'layer': 'macrocounty', |
||||
'macrocounty': 'macrocounty name', |
||||
'region_a': 'region abbr', |
||||
'region': 'region name', |
||||
'macroregion': 'macroregion name', |
||||
'country_a': 'CAN', |
||||
'country': 'Canada' |
||||
}; |
||||
t.equal(generator(doc),'macrocounty name, region abbr, Canada'); |
||||
t.end(); |
||||
}); |
||||
|
||||
test('region', function(t) { |
||||
var doc = { |
||||
'name': 'region name', |
||||
'layer': 'region', |
||||
'region_a': 'region abbr', |
||||
'region': 'region name', |
||||
'macroregion': 'macroregion name', |
||||
'country_a': 'CAN', |
||||
'country': 'Canada' |
||||
}; |
||||
t.equal(generator(doc),'region name, Canada'); |
||||
t.end(); |
||||
}); |
||||
|
||||
test('macroregion', function(t) { |
||||
var doc = { |
||||
'name': 'macroregion name', |
||||
'layer': 'macroregion', |
||||
'macroregion': 'macroregion name', |
||||
'country_a': 'CAN', |
||||
'country': 'Canada' |
||||
}; |
||||
t.equal(generator(doc),'macroregion name, Canada'); |
||||
t.end(); |
||||
}); |
||||
|
||||
test('country', function(t) { |
||||
var doc = { |
||||
'name': 'Canada', |
||||
'layer': 'country', |
||||
'country_a': 'CAN', |
||||
'country': 'Canada' |
||||
}; |
||||
t.equal(generator(doc),'Canada'); |
||||
t.end(); |
||||
}); |
||||
|
||||
test('region should be used when region_a is not available', function(t) { |
||||
var doc = { |
||||
'name': 'locality name', |
||||
'layer': 'region', |
||||
'locality': 'locality name', |
||||
'localadmin': 'localadmin name', |
||||
'county': 'county name', |
||||
'macrocounty': 'macrocounty name', |
||||
'region': 'region name', |
||||
'macroregion': 'macroregion name', |
||||
'country_a': 'CAN', |
||||
'country': 'Canada' |
||||
}; |
||||
t.equal(generator(doc),'locality name, region name, Canada', 'region should be used'); |
||||
t.end(); |
||||
}); |
||||
|
||||
}; |
||||
|
||||
module.exports.all = function (tape, common) { |
||||
|
||||
function test(name, testFunction) { |
||||
return tape('label generator (CAN): ' + name, testFunction); |
||||
} |
||||
|
||||
for( var testCase in module.exports.tests ){ |
||||
module.exports.tests[testCase](test, common); |
||||
} |
||||
}; |
@ -1,51 +0,0 @@
|
||||
|
||||
var generator = require('../../../helper/labelGenerator'); |
||||
|
||||
module.exports.tests = {}; |
||||
|
||||
module.exports.tests.interface = function(test, common) { |
||||
test('interface', function(t) { |
||||
t.equal(typeof generator, 'function', 'valid function'); |
||||
t.end(); |
||||
}); |
||||
}; |
||||
|
||||
// SGP region
|
||||
module.exports.tests.north_west_singapore = function(test, common) { |
||||
test('north west singapore', function(t) { |
||||
var doc = { |
||||
'name': 'North West', |
||||
'country_a': 'SGP', |
||||
'country': 'Singapore', |
||||
'region': 'North West' |
||||
}; |
||||
t.equal(generator(doc),'North West, Singapore'); |
||||
t.end(); |
||||
}); |
||||
}; |
||||
|
||||
// SGP venue
|
||||
module.exports.tests.singapore_mcdonalds = function(test, common) { |
||||
test('singapore_mcdonalds', function(t) { |
||||
var doc = { |
||||
'name': 'McDonald\'s', |
||||
'country_a': 'SGP', |
||||
'country': 'Singapore', |
||||
'region': 'Central Singapore', |
||||
'locality': 'Singapore' |
||||
}; |
||||
t.equal(generator(doc),'McDonald\'s, Central Singapore, Singapore'); |
||||
t.end(); |
||||
}); |
||||
}; |
||||
|
||||
module.exports.all = function (tape, common) { |
||||
|
||||
function test(name, testFunction) { |
||||
return tape('label generator: ' + name, testFunction); |
||||
} |
||||
|
||||
for( var testCase in module.exports.tests ){ |
||||
module.exports.tests[testCase](test, common); |
||||
} |
||||
}; |
@ -1,53 +0,0 @@
|
||||
|
||||
var generator = require('../../../helper/labelGenerator'); |
||||
|
||||
module.exports.tests = {}; |
||||
|
||||
module.exports.tests.interface = function(test, common) { |
||||
test('interface', function(t) { |
||||
t.equal(typeof generator, 'function', 'valid function'); |
||||
t.end(); |
||||
}); |
||||
}; |
||||
|
||||
// SWE city
|
||||
module.exports.tests.skane1 = function(test, common) { |
||||
test('skĂĄne 1', function(t) { |
||||
var doc = { |
||||
'name': 'Malmö', |
||||
'country_a': 'SWE', |
||||
'country': 'Sweden', |
||||
'region': 'SkĂĄne', |
||||
'county': 'Malmö' |
||||
}; |
||||
t.equal(generator(doc),'Malmö, Skåne, Sweden'); |
||||
t.end(); |
||||
}); |
||||
}; |
||||
|
||||
// SWE city
|
||||
module.exports.tests.skane2 = function(test, common) { |
||||
test('skĂĄne 2', function(t) { |
||||
var doc = { |
||||
'name': 'Malmö', |
||||
'country_a': 'SWE', |
||||
'country': 'Sweden', |
||||
'region': 'SkĂĄne', |
||||
'county': 'Malmö', |
||||
'locality': 'Malmö' |
||||
}; |
||||
t.equal(generator(doc),'Malmö, Skåne, Sweden'); |
||||
t.end(); |
||||
}); |
||||
}; |
||||
|
||||
module.exports.all = function (tape, common) { |
||||
|
||||
function test(name, testFunction) { |
||||
return tape('label generator: ' + name, testFunction); |
||||
} |
||||
|
||||
for( var testCase in module.exports.tests ){ |
||||
module.exports.tests[testCase](test, common); |
||||
} |
||||
}; |
@ -0,0 +1,116 @@
|
||||
var generator = require('../../../helper/labelGenerator'); |
||||
|
||||
module.exports.tests = {}; |
||||
|
||||
module.exports.tests.interface = function(test, common) { |
||||
test('interface', function(t) { |
||||
t.equal(typeof generator, 'function', 'valid function'); |
||||
t.end(); |
||||
}); |
||||
}; |
||||
|
||||
module.exports.tests.canada = function(test, common) { |
||||
test('venue', function(t) { |
||||
var doc = { |
||||
'name': 'Tim Horton\'s', |
||||
'layer': 'venue', |
||||
'housenumber': '1', |
||||
'street': 'Main St', |
||||
'neighbourhood': 'College Heights', |
||||
'locality': 'Thunder Bay', |
||||
'region_a': 'ON', |
||||
'region': 'Ontario', |
||||
'country_a': 'CAN', |
||||
'country': 'Canada' |
||||
}; |
||||
t.equal(generator(doc),'Tim Horton\'s, Thunder Bay, ON, Canada'); |
||||
t.end(); |
||||
}); |
||||
|
||||
test('address', function(t) { |
||||
var doc = { |
||||
'name': '1 Main St', |
||||
'layer': 'venue', |
||||
'housenumber': '1', |
||||
'street': 'Main St', |
||||
'locality': 'Truth or Consequences', |
||||
'region_a': 'NM', |
||||
'region': 'New Mexico', |
||||
'country_a': 'USA', |
||||
'country': 'United States' |
||||
}; |
||||
t.equal(generator(doc),'1 Main St, Truth or Consequences, NM, USA'); |
||||
t.end(); |
||||
}); |
||||
}; |
||||
|
||||
module.exports.tests.france = function(test, common) { |
||||
test('eiffel tower', function(t) { |
||||
var doc = { |
||||
'name': 'Tour Eiffel', |
||||
'layer': 'venue', |
||||
'neighbourhood': 'Quartier du Gros-Caillou', |
||||
'locality': 'Paris', |
||||
'region': 'Paris', |
||||
'country_a': 'FRA', |
||||
'country': 'France' |
||||
}; |
||||
t.equal(generator(doc),'Tour Eiffel, Paris, France'); |
||||
t.end(); |
||||
}); |
||||
|
||||
test('France street address', function(t) { |
||||
var doc = { |
||||
'name': '74 rue de rivoli', |
||||
'layer': 'address', |
||||
'housenumber': '74', |
||||
'street': 'Rue de Rivoli', |
||||
'neighbourhood': 'Quartier Saint-Merri', |
||||
'locality': 'Paris', |
||||
'region': 'Paris', |
||||
'country_a': 'FRA', |
||||
'country': 'France' |
||||
}; |
||||
t.equal(generator(doc),'74 rue de rivoli, Paris, France'); |
||||
t.end(); |
||||
}); |
||||
|
||||
test('France neighbourhood', function(t) { |
||||
var doc = { |
||||
'name': 'Grange aux Belles Terrage', |
||||
'layer': 'neighbourhood', |
||||
'neighbourhood': 'Grange aux Belles Terrage', |
||||
'locality': 'Paris', |
||||
'region': 'Paris', |
||||
'country_a': 'FRA', |
||||
'country': 'France' |
||||
}; |
||||
t.equal(generator(doc),'Grange aux Belles Terrage, Paris, France'); |
||||
t.end(); |
||||
}); |
||||
|
||||
test('Luxembourg (the city) in Luxembourg', function(t) { |
||||
var doc = { |
||||
'name': 'Luxembourg', |
||||
'layer': 'locality', |
||||
'locality': 'Luxembourg', |
||||
'country_a': 'LUX', |
||||
'country': 'Luxembourg' |
||||
}; |
||||
// console.error(generator(doc));
|
||||
t.equal(generator(doc),'Luxembourg, Luxembourg'); |
||||
t.end(); |
||||
}); |
||||
|
||||
}; |
||||
|
||||
module.exports.all = function (tape, common) { |
||||
|
||||
function test(name, testFunction) { |
||||
return tape('label generator (CAN): ' + name, testFunction); |
||||
} |
||||
|
||||
for( var testCase in module.exports.tests ){ |
||||
module.exports.tests[testCase](test, common); |
||||
} |
||||
}; |
Loading…
Reference in new issue