Browse Source

expose id/type/layer

pull/38/head
Peter Johnson 10 years ago
parent
commit
6efa0aa510
  1. 9
      helper/geojsonify.js
  2. 14
      service/mget.js
  3. 6
      service/search.js
  4. 6
      test/unit/controller/search.js
  5. 6
      test/unit/controller/suggest.js
  6. 10
      test/unit/helper/geojsonify.js
  7. 10
      test/unit/mock/backend.js

9
helper/geojsonify.js

@ -14,11 +14,16 @@ function search( docs ){
// flatten & expand data for geojson conversion
var geodata = docs.map( function( doc ){
var output = {};
// something went very wrong
if( !doc ) return warning();
var output = {};
// provide metadata to consumer
output.id = doc._id;
output.type = doc._type;
output.layer = doc._type;
// map center_point
if( !doc.center_point ) return warning();
output.lat = parseFloat( doc.center_point.lat );

14
service/mget.js

@ -29,7 +29,19 @@ function service( backend, query, cb ){
// map returned documents
var docs = [];
if( data && Array.isArray(data.docs) ){
docs = data.docs.map( function( doc ){
docs = data.docs.filter( function( doc ){
// remove docs not actually found
return doc.found;
}).map( function( doc ){
// map metadata in to _source so we
// can serve it up to the consumer
doc._source._id = doc._id;
doc._source._type = doc._type;
return doc._source;
});
}

6
service/search.js

@ -17,6 +17,12 @@ function service( backend, cmd, cb ){
var docs = [];
if( data && data.hits && data.hits.total && Array.isArray(data.hits.hits)){
docs = data.hits.hits.map( function( hit ){
// map metadata in to _source so we
// can serve it up to the consumer
hit._source._id = hit._id;
hit._source._type = hit._type;
return hit._source;
});
}

6
test/unit/controller/search.js

@ -24,6 +24,9 @@ module.exports.tests.functional_success = function(test, common) {
coordinates: [ -50.5, 100.1 ]
},
properties: {
id: 'myid1',
type: 'mytype1',
layer: 'mytype1',
name: 'test name1',
admin0: 'country1',
admin1: 'state1',
@ -37,6 +40,9 @@ module.exports.tests.functional_success = function(test, common) {
coordinates: [ -51.5, 100.2 ]
},
properties: {
id: 'myid2',
type: 'mytype2',
layer: 'mytype2',
name: 'test name2',
admin0: 'country2',
admin1: 'state2',

6
test/unit/controller/suggest.js

@ -24,6 +24,9 @@ module.exports.tests.functional_success = function(test, common) {
coordinates: [ -50.5, 100.1 ]
},
properties: {
id: 'myid1',
type: 'mytype1',
layer: 'mytype1',
name: 'test name1',
admin0: 'country1',
admin1: 'state1',
@ -37,6 +40,9 @@ module.exports.tests.functional_success = function(test, common) {
coordinates: [ -51.5, 100.2 ]
},
properties: {
id: 'myid2',
type: 'mytype2',
layer: 'mytype2',
name: 'test name2',
admin0: 'country2',
admin1: 'state2',

10
test/unit/helper/geojsonify.js

@ -15,6 +15,8 @@ module.exports.tests.search = function(test, common) {
var input = [
{
"_id": "id1",
"_type": "type1",
"center_point": {
"lat": 51.5337144,
"lon": -0.1069716
@ -48,6 +50,8 @@ module.exports.tests.search = function(test, common) {
}
},
{
"_id": "id2",
"_type": "type2",
"type": "way",
"name": {
"default": "Blues Cafe"
@ -90,6 +94,9 @@ module.exports.tests.search = function(test, common) {
]
},
"properties": {
"id": "id1",
"type": "type1",
"layer": "type1",
"text": "'Round Midnight Jazz and Blues Bar, Angel, United Kingdom",
"name": "'Round Midnight Jazz and Blues Bar",
"alpha3": "GBR",
@ -112,6 +119,9 @@ module.exports.tests.search = function(test, common) {
]
},
"properties": {
"id": "id2",
"type": "type2",
"layer": "type2",
"text": "Blues Cafe, Smithfield, United Kingdom",
"name": "Blues Cafe",
"alpha3": "GBR",

10
test/unit/mock/backend.js

@ -9,6 +9,8 @@ responses['client/suggest/fail/1'] = function( cmd, cb ){
};
responses['client/search/ok/1'] = function( cmd, cb ){
return cb( undefined, searchEnvelope([{
_id: 'myid1',
_type: 'mytype1',
_source: {
value: 1,
center_point: { lat: 100.1, lon: -50.5 },
@ -16,6 +18,8 @@ responses['client/search/ok/1'] = function( cmd, cb ){
admin0: 'country1', admin1: 'state1', admin2: 'city1'
}
}, {
_id: 'myid2',
_type: 'mytype2',
_source: {
value: 2,
center_point: { lat: 100.2, lon: -51.5 },
@ -26,6 +30,9 @@ responses['client/search/ok/1'] = function( cmd, cb ){
};
responses['client/mget/ok/1'] = function( cmd, cb ){
return cb( undefined, mgetEnvelope([{
_id: 'myid1',
_type: 'mytype1',
found: true,
_source: {
value: 1,
center_point: { lat: 100.1, lon: -50.5 },
@ -33,6 +40,9 @@ responses['client/mget/ok/1'] = function( cmd, cb ){
admin0: 'country1', admin1: 'state1', admin2: 'city1'
}
}, {
_id: 'myid2',
_type: 'mytype2',
found: true,
_source: {
value: 2,
center_point: { lat: 100.2, lon: -51.5 },

Loading…
Cancel
Save