Browse Source

Merge branch 'master' of github.com:pelias/api into confidence

pull/219/head
Diana Shkolnikov 9 years ago
parent
commit
771c5563ec
  1. 81
      helper/geojsonify.js
  2. 2
      test/ciao/index.coffee
  3. 2
      test/ciao/place/msuccess.coffee
  4. 2
      test/ciao/place/success.coffee
  5. 2
      test/ciao/reverse/success.coffee
  6. 2
      test/ciao/search/success.coffee
  7. 2
      test/ciao/suggest/nearby_nobias.coffee
  8. 2
      test/ciao/suggest/success.coffee
  9. 2
      test/ciao/suggest/success_nearby.coffee

81
helper/geojsonify.js

@ -1,7 +1,9 @@
var GeoJSON = require('geojson'), var GeoJSON = require('geojson');
extent = require('geojson-extent'), var extent = require('geojson-extent');
outputGenerator = require('./outputGenerator'); var outputGenerator = require('./outputGenerator');
var logger = require('pelias-logger').get('api');
// Properties to be copied when details=true // Properties to be copied when details=true
var DETAILS_PROPS = [ var DETAILS_PROPS = [
@ -20,20 +22,62 @@ var DETAILS_PROPS = [
'confidence' 'confidence'
]; ];
var META_MAP = {
'geoname': { type: '???', source: 'gn' }, // TODO: not sure how to map. will need to use categories? var SOURCES = {
'osmnode': { type: 'venue', source: 'osm' }, 'geoname': 'gn',
'osmway': { type: 'venue', source: 'osm' }, 'osmnode': 'osm',
'admin0': { type: 'country', source: 'qs' }, 'osmway': 'osm',
'admin1': { type: 'region', source: 'qs' }, 'admin0': 'qs',
'admin2': { type: 'county', source: 'qs' }, 'admin1': 'qs',
'neighborhood': { type: 'neighbourhood', source: 'qs' }, 'admin2': 'qs',
'locality': { type: 'locality', source: 'qs' }, 'neighborhood': 'qs',
'local_admin': { type: 'local_admin', source: 'qs' }, 'locality': 'qs',
'osmaddress': { type: 'address', source: 'osm' }, 'local_admin': 'qs',
'openaddresses': { type: 'address', source: 'oa' } 'osmaddress': 'osm',
'openaddresses': 'oa'
}; };
function lookupSource(src) {
return SOURCES.hasOwnProperty(src._type) ? SOURCES[src._type] : src._type;
}
function lookupLayer(src) {
switch(src._type) {
case 'osmnode':
case 'osmway':
return 'venue';
case 'admin0':
return 'country';
case 'admin1':
return 'region';
case 'admin2':
return 'county';
case 'neighborhood':
return 'neighbourhood';
case 'locality':
return 'locality';
case 'local_admin':
return 'localadmin';
case 'osmaddress':
case 'openaddresses':
return 'address';
case 'geoname':
if (src.category && src.category.indexOf('admin') !== -1) {
if (src.category.indexOf('admin:city') !== -1) { return 'locality'; }
if (src.category.indexOf('admin:admin1') !== -1) { return 'region'; }
if (src.category.indexOf('admin:admin2') !== -1) { return 'county'; }
return 'neighbourhood'; // this could also be 'local_admin'
}
if (src.name) { return 'venue'; }
if (src.address) { return 'address'; }
}
logger.warn('[geojsonify]: could not map _type ', src._type);
return src._type;
}
function geojsonifyPlaces( docs, params ){ function geojsonifyPlaces( docs, params ){
var details = params ? params.details : {}; var details = params ? params.details : {};
@ -149,12 +193,9 @@ function copyProperties( source, props, dst ) {
* @param {object} dst * @param {object} dst
*/ */
function addMetaData(src, dst) { function addMetaData(src, dst) {
// lookup mapping, or set both values to _type if not found
var meta = META_MAP[src._type] || { type: src._type, source: src._type };
dst.id = src._id; dst.id = src._id;
dst.layer = meta.type; dst.layer = lookupLayer(src);
dst.source = meta.source; dst.source = lookupSource(src);
} }
/** /**

2
test/ciao/index.coffee

@ -1,6 +1,6 @@
#> api root #> api root
path: '/' path: '/v1/'
#? endpoint available #? endpoint available
response.statusCode.should.equal 200 response.statusCode.should.equal 200

2
test/ciao/place/msuccess.coffee

@ -1,6 +1,6 @@
#> valid place query #> valid place query
path: '/place?id=geoname:4221195&id=geoname:4193595' path: '/v1/place?id=geoname:4221195&id=geoname:4193595'
#? 200 ok #? 200 ok
response.statusCode.should.equal 200 response.statusCode.should.equal 200

2
test/ciao/place/success.coffee

@ -1,6 +1,6 @@
#> valid place query #> valid place query
path: '/place?id=geoname:4221195' path: '/v1/place?id=geoname:4221195'
#? 200 ok #? 200 ok
response.statusCode.should.equal 200 response.statusCode.should.equal 200

2
test/ciao/reverse/success.coffee

@ -1,5 +1,5 @@
#> valid reverse query #> valid reverse query
path: '/reverse?lat=29.49136&lon=-82.50622' path: '/v1/reverse?lat=29.49136&lon=-82.50622'
#? 200 ok #? 200 ok
response.statusCode.should.equal 200 response.statusCode.should.equal 200

2
test/ciao/search/success.coffee

@ -1,5 +1,5 @@
#> valid search query #> valid search query
path: '/search?input=lake&lat=29.49136&lon=-82.50622' path: '/v1/search?input=lake&lat=29.49136&lon=-82.50622'
#? 200 ok #? 200 ok
response.statusCode.should.equal 200 response.statusCode.should.equal 200

2
test/ciao/suggest/nearby_nobias.coffee

@ -1,6 +1,6 @@
#> suggest without geo bias #> suggest without geo bias
path: '/suggest/nearby?input=a' path: '/v1/suggest/nearby?input=a'
#? 400 bad request #? 400 bad request
response.statusCode.should.equal 400 response.statusCode.should.equal 400

2
test/ciao/suggest/success.coffee

@ -1,6 +1,6 @@
#> valid suggest query #> valid suggest query
path: '/suggest?input=a&lat=0&lon=0' path: '/v1/suggest?input=a&lat=0&lon=0'
#? 200 ok #? 200 ok
response.statusCode.should.equal 200 response.statusCode.should.equal 200

2
test/ciao/suggest/success_nearby.coffee

@ -1,6 +1,6 @@
#> valid suggest query #> valid suggest query
path: '/suggest/nearby?input=a&lat=29.49136&lon=-82.50622' path: '/v1/suggest/nearby?input=a&lat=29.49136&lon=-82.50622'
#? 200 ok #? 200 ok
response.statusCode.should.equal 200 response.statusCode.should.equal 200

Loading…
Cancel
Save