Browse Source

Build responses with new source and layer fields

There is no longer any ambiguity in the source field and the layer
(which is stored as _type), so a lot of logic to compute them can simply
read from the elasticsearch document. Hooray!
pull/407/head
Julian Simioni 9 years ago
parent
commit
cdd00af6bc
  1. 21
      helper/geojsonify.js
  2. 25
      test/unit/helper/geojsonify.js

21
helper/geojsonify.js

@ -25,8 +25,7 @@ var DETAILS_PROPS = [
function lookupSource(src) { function lookupSource(src) {
var sources = type_mapping.type_to_source; return src.source;
return sources.hasOwnProperty(src._type) ? sources[src._type] : src._type;
} }
/* /*
@ -34,24 +33,6 @@ function lookupSource(src) {
* Elasticsearch document source allows a more specific layer name to be chosen * Elasticsearch document source allows a more specific layer name to be chosen
*/ */
function lookupLayer(src) { function lookupLayer(src) {
if (src._type === 'geoname') {
if (_.includes(src.category, 'admin')) {
if (_.includes(src.category, 'admin:city')) { return 'locality'; }
if (_.includes(src.category, 'admin:admin1')) { return 'region'; }
if (_.includes(src.category, 'admin:admin2')) { return 'county'; }
return 'neighbourhood'; // this could also be 'local_admin'
}
if (src.name) { return 'venue'; }
if (src.address) { return 'address'; }
}
if (_.includes(type_mapping.types, src._type)) {
return type_mapping.type_to_layer[src._type];
}
logger.warn('[geojsonify]: could not map _type ', src._type);
return src._type; return src._type;
} }

25
test/unit/helper/geojsonify.js

@ -40,7 +40,8 @@ module.exports.tests.search = function(test, common) {
var input = [ var input = [
{ {
'_id': 'id1', '_id': 'id1',
'_type': 'type1', '_type': 'layer1',
'source': 'source1',
'center_point': { 'center_point': {
'lat': 51.5337144, 'lat': 51.5337144,
'lon': -0.1069716 'lon': -0.1069716
@ -72,7 +73,8 @@ module.exports.tests.search = function(test, common) {
}, },
{ {
'_id': 'id2', '_id': 'id2',
'_type': 'type2', '_type': 'layer2',
'source': 'source2',
'name': { 'name': {
'default': 'Blues Cafe' 'default': 'Blues Cafe'
}, },
@ -97,7 +99,8 @@ module.exports.tests.search = function(test, common) {
}, },
{ {
'_id': '34633854', '_id': '34633854',
'_type': 'osmway', '_type': 'way',
'source': 'osm',
'name': { 'name': {
'default': 'Empire State Building' 'default': 'Empire State Building'
}, },
@ -141,9 +144,9 @@ module.exports.tests.search = function(test, common) {
}, },
'properties': { 'properties': {
'id': 'id1', 'id': 'id1',
'gid': 'type1:type1:id1', 'gid': 'source1:layer1:id1',
'layer': 'type1', 'layer': 'layer1',
'source': 'type1', 'source': 'source1',
'label': '\'Round Midnight Jazz and Blues Bar, test3, Angel', 'label': '\'Round Midnight Jazz and Blues Bar, test3, Angel',
'name': '\'Round Midnight Jazz and Blues Bar', 'name': '\'Round Midnight Jazz and Blues Bar',
'country_a': 'GBR', 'country_a': 'GBR',
@ -170,9 +173,9 @@ module.exports.tests.search = function(test, common) {
}, },
'properties': { 'properties': {
'id': 'id2', 'id': 'id2',
'gid': 'type2:type2:id2', 'gid': 'source2:layer2:id2',
'layer': 'type2', 'layer': 'layer2',
'source': 'type2', 'source': 'source2',
'label': 'Blues Cafe, test3, Smithfield', 'label': 'Blues Cafe, test3, Smithfield',
'name': 'Blues Cafe', 'name': 'Blues Cafe',
'country_a': 'GBR', 'country_a': 'GBR',
@ -196,8 +199,8 @@ module.exports.tests.search = function(test, common) {
}, },
'properties': { 'properties': {
'id': '34633854', 'id': '34633854',
'gid': 'osm:venue:34633854', 'gid': 'osm:way:34633854',
'layer': 'venue', 'layer': 'way',
'source': 'osm', 'source': 'osm',
'label': 'Empire State Building, Manhattan, NY, USA', 'label': 'Empire State Building, Manhattan, NY, USA',
'name': 'Empire State Building', 'name': 'Empire State Building',

Loading…
Cancel
Save